Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > single instance

Reply
Thread Tools

single instance

 
 
Knute Johnson
Guest
Posts: n/a
 
      01-16-2013
On 1/15/2013 10:51 PM, Roedy Green wrote:
> On Sat, 05 Jan 2013 19:49:08 -0800, Knute Johnson
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
> who said :
>
>>
>> The risk is, that in Windows anyway, where the system clock granularity
>> is 17ms it is possible to start two copies of a program with a batch

>
> I have been studying Knute's code and Peter's commentary hoping to
> come up with a canned package for ensuring single Instance.
>
> Using system.nanotime aught to help avoid granularity trouble.


The problem with nanotime is that it is not guaranteed to use the same
starting point on different invocations of the VM. The granularity of
currentTimeMillis in Windows is large but not on Linux.

> I am puzzled about "227.228.229.230" the IP used. Where did that
> value come from? Can this be made to work with IPV6?


Arbitrary choice by me of a valid Multicast IP. I don't know any reason
why it would not work with IPV6 but I've never seen any discussion of it.


--

Knute Johnson
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      01-16-2013
On 1/15/2013 11:16 PM, Roedy Green wrote:
> On Tue, 15 Jan 2013 22:51:45 -0800, Roedy Green
> <(E-Mail Removed)> wrote, quoted or indirectly quoted
> someone who said :
>
>>
>> I have been studying Knute's code and Peter's commentary hoping to
>> come up with a canned package for ensuring single Instance.

>
> If you had two machines on a LAN, would they prevent the other from
> running a new instance? You don't want, that, just on the same
> machine.
>
> If you wanted that behaviour -- e.g. to enforce a single instance
> licence across the LAN, what do you do have make the all one group?
>


Same IP and port.

--

Knute Johnson
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      01-16-2013
On 1/16/2013 1:51 AM, Roedy Green wrote:
> On Sat, 05 Jan 2013 19:49:08 -0800, Knute Johnson
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
> who said :
>> The risk is, that in Windows anyway, where the system clock granularity
>> is 17ms it is possible to start two copies of a program with a batch

>
> I have been studying Knute's code and Peter's commentary hoping to
> come up with a canned package for ensuring single Instance.
>
> Using system.nanotime aught to help avoid granularity trouble.


1) It uses a smaller unit, but does not guarantee a smaller
granularity.

2) It is only guaranteed to work within the same program as
the base is not fixed.

3) No matter how small a granularity, then it still just reduces
the risk of concurrency problems but does not eliminate the risk.

Arne




 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      01-16-2013
On 1/16/2013 3:13 AM, Peter Duniho wrote:
> On Tue, 15 Jan 2013 23:50:05 -0800, Roedy Green wrote:
>> You ask the OS , please assign me a free port. Here is a UUID. If
>> anyone asks for a port presenting the same UUID, please give him the
>> same one, no matter if he is calling from within the machine or
>> without. With such a scheme, you would not need reserved ports
>> (except for the port assigning port), and you could not have
>> collisions. Internally arrays of sockets could be dense. You can
>> then hard code in UUIDs into apps. Users don't need to worry about
>> collisions. Perhaps in IPV8.

>
> Since the problem is solveable using the existing mechanisms, I don't see a
> compelling reason the above feature should be included in future versions
> of IP.
>
> Also, I'm no expert, but I'm not sure that any of the IP specifications
> concern themselves with ports at all. That might be at the TCP and UDP
> protocol levels, independent of the IP stuff.


Port numbers are indeed in the TCP and UDP header not in the IP header.

Arne

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-16-2013
On Wed, 16 Jan 2013 07:28:38 -0800, Peter Duniho
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>> the UUID would be the port. The 16-bit port would just be an shorthand
>> abbreviation for it.

>
>We call that, in the programming community, a "hash code". It's not
>unique, and therefore not useful as an actual port ID.



A hash is different. The assignment process might work with a HashMap
or like a HashMap. If hashes collide you assign different 16 bit
numbers. It is a dynamic process. You don't always get the same 16
bit port from the same UUID.

If you are sure the port is reserved for you, you just use the 16 bit
version. If not, you ask for a port reservation (good for perhaps one
second) given the UUID. Then you use the 16 bit port. When you close
it, the reservation disappears.
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-16-2013
On Wed, 16 Jan 2013 08:46:42 -0800, Knute Johnson
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>
>Same IP and port.


But how far does this ripple?
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      01-16-2013
On 1/16/2013 10:46 AM, Roedy Green wrote:
> On Wed, 16 Jan 2013 08:46:42 -0800, Knute Johnson
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
> who said :
>
>>
>> Same IP and port.

>
> But how far does this ripple?
>



As far as I know, it only works on your network segment. Only for
machines connected to the same physical router or gateway.

The multicast stuff is really more of a router protocol. A machine
broadcasts to one or more addresses, and the routers along the way take
care of passing the stream to interested client machines.

Also note that as far as I know, absolutely no routers implement this.
It's a dead protocol.

 
Reply With Quote
 
stledger@lanl.gov
Guest
Posts: n/a
 
      01-16-2013
On Tuesday, January 1, 2013 1:23:45 PM UTC-7, Roedy Green wrote:
> What is the best way to ensure only a single instance of a Java program is running. I have used indicator files, but they can get screwed up if the user kills the program without going through the standard shutdown. Ideally, net new instance would just join the one already running. This is pure GUI, so I am not worried about adding new command line parms. -- Roedy Green Canadian Mind Products http://mindprod.com Students who hire or con others to do their homework are as foolish as couch potatoes who hire others to goto the gym for them.


I worked on a project with a requirement to run only one instance of our software at a time. We had a configuration file that had initialization values for the software. If the file was missing, then the code had default values. The code was running on one computer. Our code worked like this:

try{
Socket sock = new Socket();
sock.bind(new InetSocketAddress(int value read from configuration file or default value));
} catch (java.net.BindException)
{ tell user they are trying to start more than one instance and shutdown this copy after user acknowledges }

It's simple and seemed to always work. We only had to worry about a user double clicking the application. We did not worry about a batch file trying to start more than one instance. Obviously, you could start one instance, delete the configuration file, then start the second instance. We judged this to be a very unlikely possibility given our users, so we didn't worry about it. The software backed up its data on shutdown, and at regular intervals, and kept several backup files going back over the last week, so it was possible to restore the data to a given time over the past week of operation. YMMV.

John
 
Reply With Quote
 
stledger@lanl.gov
Guest
Posts: n/a
 
      01-16-2013
On Wednesday, January 16, 2013 3:51:57 PM UTC-7, (E-Mail Removed) wrote:
> On Tuesday, January 1, 2013 1:23:45 PM UTC-7, Roedy Green wrote: > What is the best way to ensure only a single instance of a Java program is running. I have used indicator files, but they can get screwed up if the user kills the program without going through the standard shutdown. Ideally, net new instance would just join the one already running. This is pure GUI, so I am not worried about adding new command line parms. -- Roedy Green CanadianMind Products http://mindprod.com Students who hire or con others to do their homework are as foolish as couch potatoes who hire others to go to the gym for them. I worked on a project with a requirement to run only one instance of our software at a time. We had a configuration file that had initialization values for the software. If the file was missing, then the code had default values. The code was running on one computer. Our code worked like this: try{ Socket sock = new Socket(); sock.bind(new InetSocketAddress(int value read from configuration file or default value)); } catch (java.net.BindException) { tell user they are trying to start more than one instance and shutdown this copy after user acknowledges } It's simple and seemed to always work. We only had to worry about a user double clicking the application. We did not worry about a batch file trying to start more than one instance. Obviously, you could start one instance, delete the configuration file, then start the second instance. We judged this to be a very unlikely possibility given our users, so we didn't worry about it. The software backed up its data on shutdown, and at regular intervals, and kept several backup files going back over the last week, so it was possible to restore the data to a given time over the past week of operation. YMMV. John


Oops! Need to catch an IOException, not a BindException!!
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      01-17-2013
On 1/16/2013 10:46 AM, Roedy Green wrote:
> On Wed, 16 Jan 2013 08:46:42 -0800, Knute Johnson
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
> who said :
>
>>
>> Same IP and port.

>
> But how far does this ripple?
>


Routers are the usual place that the Multicast packet is stopped. But
you could certainly use it in your local network.

--

Knute Johnson
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Taglib problems - instead of a single instance per page, I have a single instance per application. chris brat Java 1 05-10-2006 11:16 AM
Problem when subclass instance changes base class instance variable Gerry Sutton Python 1 04-16-2005 06:06 AM
Accessing an instance via its memory address (instance at ...) Kent Johnson Python 4 11-13-2004 07:42 PM
converting base class instance to derived class instance Sridhar R Python 14 02-10-2004 02:47 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM



Advertisments