Stop Multiple Instances of an application

Hello

The title pretty much says it all that, I was wondering if I could gather your comments on how to properly stop an application running more than once in java. I've implemented the two methods of file locking and ServerSockets, but both have their drawbacks. For example, file locking seems to cause a problem that the file is unlocked / deleted if the process is terminated abnormally, and I still have to come up with a solution for this other than to create a batch file for auto run... Similarly, with the ServerSocket there doesn't seem to be very reliable, it runs for a few moments, and then disappears without error message...

I searched the web and found something called JUnique claiming to do what I'm after but I'm not sure if it would work the way that I'm after, as seems to be implying that works with the file locking method.

Anyway, how do you solve this in your applications?

Thank you very much
Barto.

PS. the other thing is that I noticed that other languages use what is called the Mutex to stop execution of an application several times - it's available in Java?

Published by: 799611 on December 4, 2010 09:18

In my example I ServerSocket ss =... This refrence exists for 30 secondsI don't see your entire program, but it is possible to have a

static ServerSocket ss = new ServerSocket(1234);

somewhere. Nobody's going to take as long as your program runs.

Tags: Java

Similar Questions

  • How to avoid creating multiple instances of the application?

    Hello

    We have a user interface Application. The application has been set to Auto run at startup and as a Module system.

    The application has a file listener that checks all new emails.

    When we start the application from the user interface by clicking on the application icon, it seems that the multiple instance of the application is created. For this reason when send us an email to request it is receiving emails several times. Sometimes simple, double and sometimes even five times.

    public class MyApplication  extends UiApplication implements FolderListener,
            SystemListener, GlobalEventListener {
    
        // Boot
        public static void main(String[] args) {
            if (args != null && args.length > 0 && args[0].equals("gui")) {
                // code to initialize the app
                fromService = false;
                // register the notification
                Notification n = new Notification();
                n.registerNotificationObjects();
    
                Utilities.writeLog(GUID, "MyApplication GUI Starting up");
                MyApplication service = new MyApplication();
                service.enterEventDispatcher();
            } else {
                Utilities.writeLog(GUID, "OnBoardV2 Service Starting up");
                MyApplication service = new MyApplication();
                service.enterEventDispatcher();
            }
        }
    
        public void messagesAdded(FolderEvent e) {
            /// Receive messages
            }   
    
    }
    

    In this regard, any help will be apreciated!

    Thank you

    I don't know if it's your entire code, but if you register your application as a file time listener never, it is called, then you save several headphones. The listener does not cause deleted your app closes, you must explicitly remove the listener. You must either put the listener in its own class and only sign up to start or find a way to check if the listener is already registered whenever the application is called.

  • Multiple Instances of the Application to access the same DAQ hardware

    I have a relatively simple application that reads from a device of data acquisition (OR-9205 connected to NI WLS-9163) wireless.  I would like to run multiple instances of the executable, but I get the error-201105 (resource reserved) as soon as the DAQmx task starts on the second instance.  Each instance tries to acquire different channels of the same DAQ hardware.  Is this a problem with the data acquisition device, or DAQmx in general?  Thank you.

    -Joe

    Hey Joe,

    Unfortunately, you can only one type of access channel with each program.  For example, you might HAVE a program access and another use AO, but you can't have two programs different AI the same access card.  It is common among all of the DAQ hardware to NEITHER.

  • How to avoid multiple instances of the application

    Hello

    I would like to know how I can to avoid multiple instances of my request, my application have an option to "invoke later" which will awaken the application after xx minutes but where the user clicks on the icon of the application, for example, a few seconds before he must wake up he will see 2 instances open my application.

    Currently, the work around I did is check at every opening, if there is already an open instance and if so to 'kill' later, but I would like to know if there is a more elegant way to do it.

    THX.

    You create a new ApplicationDescriptor - you say the BlackBerry OS that it is a new Application.

    If you use this method, and then the user clicks on the new icon, they will get also running two instances.  Here is a code that restarts the application 'running', that I think that it what you want.

    ApplicationDescriptor current = ApplicationDescriptor.currentApplicationDescriptor ();
    ApplicationManager.getApplicationManager (.scheduleApplication) (current, System.currentTimeMillis (+ 2001), true);
    System.Exit (0);

  • get all the screws in memory on multiple instances of application LabVIEW

    I try to get references to all of the screws in memory on multiple instances of LabVIEW application. Specifically, I'm trying to get the VI Refs screw (and their subVIs in memory) in another Explorer of projects at design time. (The other screws do not work.) For example, if you are only interested in VIs in the current instance of App (read the Project Explorer), you can use the following code:

    However, if you have multiple projects open, how can you get the references VI to the screw in the other project? It seems to me that it would be an another App Ref, but I guess I don't know how to get this reference. I'm assuming that if I could get this reference, I could use it in the same way as above for the list of App.AllVIs.

    Any help/clues would be appreciated. Thank you.

    I just tried the code below.  It runs in a single project; I have also open a second project with more than 300 screws and it opens a reference to each one without any error.  Are you the application instance reference wiring open Reference VI?

  • How to communicate between instances of Labview application?

    Hello, I have a question on how to communicate data between two instances of labview application on different computers connected via a network.

    I'll explain what I'm doing:

    I have a data acquisition program that was divided into two independent parts. The backend is responisible for the acquisition of data from several DAQ hardware, and the interface simply displays the data collected. The two parties are coupled by events in labview. The backend sends a new event data (for any one listening) whenever he gets new data and the frontend listens to these events and updates of some graphics on the front panel each time it receives this event. Other than the two parties have no communication.

    Now it is necessary to split the frontend and backend on two different computers, connected via a network. The backend will be connected to DAQ devices as usual, but the frontend is running on another computer.

    So my questions are: will be the my current communication mechanism still work on multiple instances of labview application? And if not, what is the best way to connect the two in a minimum amount of new code, and without interrupting the current program, if I decided to their port of return on the same computer?

    (I thought that a kind of middle-man would be the best who is responsible for networking).

    Please, any advice will be useful!

    Paul.

    I think that the best way to do this is a TCP/IP link.  You can do it, as you suggested, with a pair of 'intermediate' screw at one end, catch you user events in a VI and send them over the network; on the other end, you receive data and turn it into an event, requiring minimal changes to the rest of your code.  The TCP/IP screws are pretty easy to use and there are good examples of LabVIEW.  NEITHER offers the Simple e-mail reference library.  You can also watch "robust TCP' Jack Hamilton of LabUseful.com (WARNING: I've never used or not even watched these screws and cannot check they are really helpful, I have seen discussion and links to them).

  • If you open multiple instances of vWorkspace fails.

    I'm pretty new to vWorkspace pls if being informative and sweet in your answers until I got up to speed, thanks.

    I have a vWorkspace environment where users can not open multiple instances of any application from their destination vWorkspace page. Let me give you an example:

    JulianTest of the user connects to vWorkspace and sees to the vWorkspace landing page which has two icons 'Production' & 'Test '. The user clicks on "Production" but also wants to open an instance of 'Test', but when he click on 'Test' it gets the error:

    Remote Desktop cannot connect to the remote computer to one of the following reasons:

    ....

    ....

    ....

    If the user does the same thing except opens first ' Test' and then try to open 'Production' then, it gets the same error. Somehow, vWorkspace does not allow more than one RDP session for any user. I tested the computer of the user remote DESKTOP connections and I can open any number of RDP sessions to different terminal servers (there are about 10 servers terminal Server in the farm!) is not something RDP.

    Can anyone suggest how can I fix?

    Technical details:

    Workstation user OS: Windows7

    Terminal servers: Windows 2003

    Broker servers: 2 x Windows 2003

    vWorkspace version: 7.5.304.547

  • Get the name of the Instance of the Application in an IOM PrePopulationAdapter

    We have at disposal of the IOM to multiple Active Directory domains. To do this, we installed a connector AD, Multiple Instances of the Application of several Instances of IT resources, while using one and the same resource object and form. Self-service console we want to request an account (Instance of the Application) to a user, and we can choose AD1, AD2, and AD3. When we choose, lets say, AD3 do we want to pre-fill the field organization name (OU in AD) with a specific organizational unit in Active Directory corresponding to the Application Instance AD3. The problem is that in the PrepopulationAdapter we have not managed to identify the instance of the application of demand.

    Here's how to get the instance of the application of demand in an adapter to prepopulate:

    prepopulate (RequestData requestData) serializable public get {RequestServiceException}
    String response = "";
    RequestBeneficiaryEntity targetEntity = requestData.getBeneficiaries () .get (0) .getTargetEntities () .get (0);
    EntityType of OIMType = targetEntity.getRequestEntityType ();
    If (entityType! = OIMType.ApplicationInstance)
    Return ' ';

    try {}
    String entitySubType = targetEntity.getEntitySubType ();
    ApplicationInstance appInst is getAppService () .findApplicationInstanceByName (entitySubType);.

    .... Continue your own code

    getAppService is the ApplicationInstanceService API.

    -Kevin

  • Use of multiple instances of the same browser...

    Hi people,

    I have a question...
    I inherited a large APEX application, it uses Oracle SSO to log.

    We are migrating the application to a new set of servers and run regression tests.
    Testers are connecting using IE6 and multiple instances of the application both on the oldTest newTest servers and opening.

    If at some point, you can:
    an application Admin user (username ADMINTEST123)  logged into the application on oldTest
    an application Admin user (username ADMINTEST123)  logged into the application on newTest
    
    an application standard user (username TEST123)  logged into the application on oldTest
    an application standard user (username TEST123)  logged into the application on newTest
    Is this supported?

    Could someone tell me or direct me to the documentation or the thread that lists which is supported / unsupported for use of browser with APEX and SSO?

    Thanks in advance,
    Gus...

    So this can I conclude that what you say and the above results we could get questions if connection users and open new windows in this sense?

    Yes, if users connect or not, if requests for pages using the same session of apex are issued different browser instances, the results may be undesirable.

    Scott

  • Multiple instances, simple applications of level

    Hi all

    I'm looking for a little guidance regarding having 2 separate EBS database instances, working from a single mid level Apps 11.5.10.
    I spent a few hours trying to dig up information on this topic (Metalink/internet), but most of the searches return top Appl sharing information of for multi mid level of nodes.

    Is it possible to run 2 databases under a middle layer? or should I clone just the whole environment? If possible, a link some with additional reading would be most appreciated.

    Thanks for any help.


    Andy.

    Hello

    You cannot configure the application for access to multiple databases at the same time. However, you can have multiple instances (CAR database) within a single application layer files - see (Note: 403347.1 - MAA road map for E-Business Suite) for more details.

    Kind regards
    Hussein

  • Multiple instances of application problem?

    Hope that someone knows something because it's very strange.

    OK here is my scenario:

    -J' have a user interface application

    -on one of the screen appears a list of pdf files

    -When the user clicks on a file the program opens with associated pdf viewer, if necessary - this is done by using the Manager API content make a registry for my application and an invocation

    -the problem is that when I open a file close, open another file, and then close the main method of my application is run again.

    -by opening the files in my application remains in the background and when the user closes the pdf my application Viewer appears in the foreground

    How it happens that several instances of the application are created? (via the main method)

    OK, this is so weird. I think that I fixed it, but I don't know yet why it suits it.

    My difficulty is that I added a listener response to the registry. Here's a sample:

    registry.setListener(new ResponseListener() {
    
      public void invocationResponseNotify(Registry registry) {
        registry.getResponse(true);
      }
    
    }
    

    registry.getResponse (true) blocks and waits for the response. This seems to be the key. After the opening different pdf files and closing then I close my fine application and no other instances of it are created.

    I'll be really really super happy to know what is happening and how is - what happened and why my fix fix it?

    For me, this solves my problem and is a solution, but it will be fine if someone gives some info on it so this thread might be useful to other people, too.

  • Reload applications multiple instances in a cluster

    My apologies if cela in another post, but did not find anything.

    I'm looking for strategies recharge vars app on multiple instances in a cluster.
    Any suggestions?

    Thank you

    Mike

    You can't change just the web root of TJS to point to where the lives of your code?

    See here:
    http://KB.Adobe.com/selfservice/viewContent.do?externalId=tn_19400

    I want to say... that is not something you're supposed to do anyway?

  • Update loop under Vi of hand / run multiple Instances

    Hey everybody,

    If I want to keep my code as modular as possible so that I can see any sub or VI.

    One of the SUB vi is permanently offices incase another output is detected. I don't want to make this mark on the main level because I don't want a huge loop in my main.vi and you won't worry about sending shift register valuse to my Subvi for him to function.

    Essentially, I have designed this subroutine Vi and am now trying to constantly be driven from a main.vi

    This hand is simply.

    Cluster of entry--> Sub VI

    Void VI retains a loop waiting for a change request action. Unfortuantely when I change the vale in main.vi the avlues in Subvi don't update. I guess that makes sense, in C, for example when you call Returns you need to wait until the end of the function call to update. Yet, as Labview is so strongly focused on taking SUB vi to do almost everything for you, I can't imagine labview is not able to update these values. I looked around and the answer seems to be global variables. I really don't want to use the because my application will become very big, but I'll use them if I need to.

    Unforunately, when I tried to use my global variable thing, it didn't work.

    1. global Var = Cluster

    2. it's in the Subvi both the main VI.

    3. when I run my code the global variable is not up-to-date on both front sides when I change one of them. I'm doing something wrong?

    A few comments.

    • You have not included the global variable
    • If you want to run multiple instances of the Subvi in parallel, it must be reentrant.
    • As the Subvi is interactive, it must be configured to display the front panel when it is called, otherwise there is no way to stop it ever.
    • All your time loops needed little expects. They have no need to turn as fast as the CPU allows, all other processes of hunger.
    • "Go to under control" is extremely complex and crawling with weird stuff like an ant farm.
      • The shift register must be initialized to avoid surprises (but you probably don't have it all)
      • Your loop runs one time too many.
      • Avoid the stress points, such as the structure of the case.
      • You can replace this whole thing with for example a table of threshold, no need to loop. (see image below).

    Good luck!

  • Explorer 8 opens multiple instances of rundll32.exe when closing

    When I close Explorer 8, rundll32.exe opens multiple instances and memory in the Task Manager go to more than 800,000 for each instance. After running this ram computer and virtually lock up the computer. If I stop the process, everything works normally until I opens and closes Explorer 8. It is repeatable and consistent.

    I use Vista Business, 4 concerts, Dell Latitude D830. Rundll32.exe have searched and found only one instance... located in C:\Windows\System32. I ran several programs of virus and malware and can't find any problems. Register is also good.

    I had similar problems with changing app crash of video files in a folder list to views of large icons.  I sent a problem report and in return had a fix, I unfortunately deleted after it corrected my problem.   I had to go to the command promp
    and in C:\Windows\System32 I had to modify the command that has been something like the pointed out below.

    Fault Module name: Mpeg2Parser.ax
    I think that if you send an error report that you receive a solution.

    It's because of the problem I had.
    Product

    Windows host process (Rundll32)

    Problem

    Stopped working

    Date

    18/06/2009 15:58

    Status

    More information

    Signature of the problem

    Additional information about the problem

    Bucket ID: 376914080

    Problem event name: APPCRASH

    Application name: RunDLL32.exe

    Application version: 6.0.6000.16386

    Application timestamp: 4549b0e1

    Fault Module name: Mpeg2Parser.ax

    Fault Module Version: 1.2.0.79

    Timestamp of Module error: 38e280dd

    Exception code: c0000005

    Exception offset: 00006210

    The system version: 6.0.6001.2.1.0.768.3

    Locale ID: 2057

    Additional information 1: fd00

    More information 2: ea6f5fe8924aaa756324d57f87834160

    Additional information 3: fd00

    Additional information 4: ea6f5fe8924aaa756324d57f87834160

  • How to force multiple instances of a process or program to run under XP?

    Sometimes, several instances of a program can execute without the user does something special, for example, you can open several instances of the Adobe Reader software if you click on the names of different files (but if you click directly on the .exe in Program Files XP opens just one instance).

    I am trying to run multiple instances of the Kindle for PC program, so I can display 2 different books or pages at a time. I guess that there is a way to do this by manually creating a shortcut or directly from the running of the KindleForPC.exe command line and play with command line parameters... someone knows it how?
    Thank you

    It really depends on how the application was written.  You can try to run as a different user and see if it works.  Right click on the shortcut of programs and select 'Run As.... "and use another user that the currently connected.  The user must have the appropriate privileges to run the program, for example a limited user may not be allowed to run the program or access any of its files or registry keys.

    John

Maybe you are looking for