I want to run single instance of my class ?

i have a class with name Abc, i want when my Abc class is
in running mode then i cant run my Abc class again untill my
Abc class not exit.
i want to do that in pure java, i have one logic but it is not
proper salution.
my logic is that when my programe is start first check a temprery file
which is created by my programe and when i want to exit then i delete
that temprery file.
but if computer is shutdown unproperly and my programe is in running mode then my file is not delete.
please any body give me help.
i m thanksfull.
Arif.

Hi,
let's make it more precise as so "if my class is in running mode" is not very precise - I guess, you are not talking of a class which has implemented the Runnable interface and is executed via "new Thread(Abc).start()". I think, you want a class, which can only have one instance of it at a time, right?
It is no problem, to make a class, which has only one instance - it is called a Singleton class - it consists of the following:
public class MySingleton extends Object // or any other class
public static final instance = new MySingleton();
//the trick here is to declare its constructor private
private MySingleton() { super(); }
// some other methods here
}There is only one instance of this class accessible via MySingleton.instance. The problem with it is, that it doesn't match your requirements, as so you are not able to instantiate this class ever again, even so you would declare the "instance" field not final and set it to null.
What you can do now is dealing with security managers - check the documentation of the newInstance() method of the Class class and the SecurityManager class, there you will find several links to documentation related with the use of an security manager.
greetings Marsian
P.S.: all these *** in the text are the letters a s s :(

Similar Messages

  • I want to run multiple instance of tomcat on same server-very Urgent

    HI all,
    I want to run multiple instance of tomcat on same server. I have created CATALINA_BASE directory and i put conf,logs,temp,webapps, and work directory. I have configured server.xml in different port. I have set the environment variables too. Though it didn't workout for me. Is there anything else i have to do for that. if so, Please assist me.
    I did all according to the tomcat 4.1running.txt
    Thanks in advance
    Ram.

    hi,
    http://www.linuxjournal.com/article/8561
    http://forum.java.sun.com/thread.jspa?threadID=515368&messageID=2458945Hit Google..
    http://www.google.com/search?q=how+to++run+multiple+instance+of+tomcat+on+same+server&client=netscape-pp&rls=com.netscape:en-US

  • How do i create a single instance of a class inside a servlet ?

    how do i create a single instance of a class inside a servlet ?
    public void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException {
    // call a class here. this class should create only single instance, //though we know servlet are multithreaded. if, at any time 10 user comes //and access this servlet still there would one and only one instance of //that class.
    How do i make my class ? class is supposed to write some info to text file.

    i have a class MyClass. this class creates a thread.
    i just want to run MyClass only once in my servlet. i am afriad, if there are 10 users access this servlet ,then 10 Myclass instance wouldbe created. i just want to avoid this. i want to make only one instance of this class.
    How do i do ?
    they have this code in the link you provided.
    public class SingletonObject
      private SingletonObject()
        // no code req'd
      public static SingletonObject getSingletonObject()
        if (ref == null)
            // it's ok, we can call this constructor
            ref = new SingletonObject();          
        return ref;
      public Object clone()
         throws CloneNotSupportedException
        throw new CloneNotSupportedException();
        // that'll teach 'em
      private static SingletonObject ref;
    }i see, they are using clone !, i dont need this. do i ? shouldi delete that method ?
    where do i put my thread's run method in this snippet ?

  • Managing Multiple threads accessing  a single instance of a class

    Hi,
    i have to redesign a class, say X, in such a way that i manage multiple threads accessing a single instance of the class, we cannot create multiple instances of X. The class looks like this:
    Class X{
    boolean isACalled=false;
    boolean isInitCalled=false;
    boolean isBCalled=false;
    A(){
    isACalled=true;
    Init(){
    if(!isACalled)
    A();
    B();
    C();
    isInitCalled=true;
    B(){
    if(!isACalled)
    A();
    isBCalled=true;
    C(){
    if(!isACalled)
    A();
    if(!isBCalled)
    B();
    }//end of class
    Init is the method that would be invoked on the single instance of this class.
    Now i cannot keep the flags as instance variables coz different threads would have differrent status of these flags at the same time, hence i can make them local, but if i make them local to one method, the others won't be able to check their status, so the only solution i can think of is to place all the flags in a hashtable local to method INIT AND INITIALIZE ALL OF them to false, as init would call other methods, it would pass the hashtable reference as an additional parameter, the methods would set the flags in the hashtable and it would be reflectecd in the original hashtable, and so all the methods can have access to the hashtable of flags and can perform their respective checks and setting of flags.
    This all would be local to one thread, so there's no question of flags of one thread mixin with the flags of some other thread.
    My question is :
    Is this the best way, would this work?
    In java, everything is pass by value, but if i pass the hashtable reference, would the changes made inside the called method to the hashtable key-value would be visible in the original hashtable declared inside the calling method of which the hashtable is local variable?

    In Java object variables are passed "by copy of reference", and primitive variables "by value".
    The solution with HashMap/Hashtable you suggest is ok, but I think you should read about ThreadLocal class:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html

  • Three iTune accounts have become mixed up on our computer.  I want to run separate instances of iTunes for each

    Three iTunes accounts have become mixed up on our computer.  I want to be able to run three instances of iTunes independently.  Thanks,

    Hey Shootist000,  Thanks for the replies.  First off, I am actually okay if we both have each other applications so I am not concerned about that. It is still unclear from what you have said as to whether I can in fact, use these two separte time machine backup to create two separate profiles on the new hard drive.  If that in fact can be done, then - will it create two copies of the apps we both have in the ROOT of the drive as well as placing all the ones we each have separately?
    And reading your second reply, makes me think that maybe the partition is the way to go to begin with and then down the road - after I am in the new iMac, I could reformat the iMac 27 with only one partion and restore my son's latest back prior to the reformat thus giving him full access to the 2 TB of the drive.
    If this is still making sense, does this mean :
    replace the 1TB with a 2TB - but have it partitione - 1.5 TB & 500 GB.
    Install(Restore using Time Machine) my latest back up prior to the  1.5 partition
    Install (Restore using Time Machine) my son's latest back up prior to the 500 gig partition
    Lastly, in order for us both to be using the partioned computer - I am assuming Switch user can no longer be used - so would we need to restart and select our respective partions in order to use the computer?   And if so, how would we each be able to be using time machine to back up - two separte external hard drives - with each one dedicated to only one partition? Or ? 
    Thanks so much.
    Ironically, I am only trying to do this so that I don't need to manually install all his apps, setting, games, blah blah for this temporary period.  :-)

  • Is running multiple instances of a class ok?

    hi guys,
    is it ok to have more than one instance of a class running?
    I have a console app that processes requests which have been saved in a db. this app does not need multithreading - but sometimes i may need to have multiple instances of the app running :-
    1) when there are too many requests in the db,
    2) or when i want to start another instance of the app to handle only specific duties.
    i mean this:
    i start my app:
    java myApp
    (the app is started once and does not stop for very long - heavy computing involved)
    then when i need another task to compute another task i start another instance (maybe with an option "specificDutyName" :
    java myApp specificDutyName
    Is this ok? no memory issues may arise?

    I think i am not able to follow your problem...
    when i do a java <AppName> <Any arguments/may be nothing>
    in reality I am starting off a JVM.
    If I do java <AppName> <Any arguments/may be nothing> again.... i would be starting of another JVM altogether..
    You may see two java.exe processes running in the task manager.. in case of a windows box.
    In such case if you may want to talk between applications running on two JVM's on the same machine.. you may need to resort to techniques like RMI and such...
    I dont think your requirement is so.. and this should be satisfied with simple multi-threading concepts.. you may start of a deamon thread that would keep on listening to a particular set of inputs.. which triggers of your new code path..
    Hope it makes sense..
    Vaibhav

  • Just a SINGLE instance of a class

    Hai !!!
    Kindly take a look at the psuedocode below and tell me if this would create just a "single" instance of class A through out my application.
    I have 3 classes A, B, C.
    class B {
      private A a1 = null;
      public C method1 () {
        getA();
        //System.out.println (a1.toString());
        return new C(a1);
      private A getA() {
        if (a1 == null) a1 = new A();
        return a1;
    } // end class BI used "System.out.println" to check if I got the same instance of class A. Is this correct?
    Note: I got the same a1.toString() printed for different clients. Is this the way to check?
    Thanks

    Thanks to all of you. I am new to this kind of
    programming. So having some difficulties.
    In my program, no matter what, only one instance of
    'B' is going to be used. It's like this: B b = new
    B(); and this 'b' is used throughout. Or I can say 'b'
    is a server object and all clients are going to look
    up to only one 'b'. So is it enough to have just this
    line of code inside the constructor of B : a1 = new
    A();
    Since there's going to be just one 'b', can I assume
    there's going to be only "one" a1??
    I feel I needn't even go into getData().
    public class B {
    A a1;
    public B() {
    a1 = new A();
    public C method1() {
    return new C(a1);
    }The clients would be using 'b'(a single instance of B)
    to access method1. So all the clients are going to get
    the same a1. Am I right?
    Thanks again !!!True, unless someone desides to use your code and makes a second B, or you do some manipulation later on and you end up making a new B. Then there are two As floating around and two Bs floating around, and you may not know it till some strange behavior occurs...

  • Running multiple instances of Premiere

    This may be a dumb question, and I admit I'm new and naive to Premiere, but I've Googled and I've searched the forums here, and I must say the only thing I've found regarding this is 5 years old. I'm a little pressed for time, so I figured this would be the quickest way to get an answer. I want to run multiple instances of Adobe Premiere Pro 4.2 on a Vista 32bit system. Is is possible, and how would I go about doing so? Thanks in advance.

    That wouldn't be so bad, except there are multiple takes per angle, and I renamed the clips in Premiere, so instead of 00023, it says Person Running. So instead of just looking at the time codes in the EDL, showing "00023 starts etc etc" it shows "Person Running etc etc" and I would have to guess as to which exact take it would be that was used.
    *edit* I just looked, and I could concievably click on the properties for each clip, and it shows the original file name, so it would be possible to rename them all to the original file name. It just looks like it's gonna take some extra work, on top of my already large load.

  • Running multiple instances of Flash IDE CS(6)

    I have a build machine compiling my fla files by running Flash.exe from command line and supplying a JSFL file as a parameter. I want to run multiple instances of Flash IDE in order to enable concurrent builds on that machine otherwise there's only one thread running on a build machine which is a resource waste.
    So, is it possible to run multiple instances of Flash IDE? Maybe there's a kind of command line switch? I have Flash CS6, but there shouldn't be that many differences with CC, isn't it?

    I dont think you can run multiple instances of flash both in CS6 and CC.
    -Sujai

  • Problem running multiple instances

    Hi,
    I want to run two instances of an existing database, means database created long ago now I want to start another instance of the database.I have modified instance_name(=tcslocal) paramater for the first instance which is still running fine and for the secend instance the parameters are like below:
    db_domain=world
    db_name=TCSlocal
    Instance_name=10glocal
    But when I am trying to up the second instance using "startup pfile=<path>"
    it is some time giving the error "ORA-01102: cannot mount database in EXCLUSIVE mode" and sometime throwing "ORA-00205: error in identifying controlfile, check alert log for more info" and so I failed to start to start the second instance.
    Please provide me a solution.
    Thanks in advance,
    Koushik

    Hi,
    I have created contron files, but I should not create the datafiles because I want to share all the datafiles. After creating control files I overcame the previous error but the current error showing in alert log is :
    ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
    ORA-01110: data file 1: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\SYSTEM01.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
    ORA-01110: data file 2: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\UNDOTBS01.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
    ORA-01110: data file 3: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\SYSAUX01.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
    ORA-01110: data file 4: 'C:\ORACLE_HOME\ORADATA\USERS01.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
    ORA-01110: data file 5: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\EXAMPLE01.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
    ORA-01110: data file 6: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\APPL_DATA.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
    ORA-01110: data file 7: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\APPL_INX.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 8 - see DBWR trace file
    ORA-01110: data file 8: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\HTML_DB.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 9 - see DBWR trace file
    ORA-01110: data file 9: 'C:\ORACLE_HOME\ORADATA\TRDB_DATA1.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 10 - see DBWR trace file
    ORA-01110: data file 10: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\BIP_DATA1.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 11 - see DBWR trace file
    ORA-01110: data file 11: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\BIP_INDEX1.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    ORA-01157: cannot identify/lock data file 12 - see DBWR trace file
    ORA-01110: data file 12: 'C:\ORACLE_HOME\ORADATA\TCSLOCAL\FLOW_1.DBF'
    ORA-27086: unable to lock file - already in use
    OSD-04002: unable to open file
    O/S-Error: (OS 5) Access is denied.
    Can any body please specify how can I share all this datafiles.
    Thanks in Advance,
    Koushik

  • Calling an instance of a class please help

    Hi all,
    I hope this is the right forum to post this topic.I am doing so cause I am dealing with servlets.In the init() method of a servlet.I want to call an instance of another class UserPresent.java .I will post the code below
    public void init() {
    UserPresent userpresent = new UserPresent();
    userpresent.initDatabase();
    }The compiler keeps complaining saying that .......
    AuthenticateServlet21.java:12: cannot resolve symbol
    symbol : class UserPresent
    location: class package1.structure.AuthenticateServlet21
    UserPresent userpresent = new UserPresent();
    I have included the package package1.structure in both the servlet code and the UserPresent code.
    Kindly let me know what could be the problem.
    Help would be appreciated
    Thanks
    AS

    The compiler can't find the UserPresent class in your servlet.
    You may need to import it ie import package1.structure.UserPresent
    What package is the UserPresent class in? What package is your servlet in? Is your class public?

  • "Only a single instance of this application can run" error when installing Flash

    I deleted Flash Player when trying to solve a Shockwave Flash Google Chrome issue, and after being unable to solve it I switched to Firefox. I now can't get the installer to open. I double-click on it, it asks me if I want to run it. I click Yes, then the window closes and the installer doesn't open. When I try running the installer again, I get the error message "Only a single instance of this application can run". I have tried everything. I closed Firefox, restarted my computer, and ran the Flash Player uninstaller. I am running Windows 8.1 64-bit with Mozilla Firefox and I am trying to run the latest version of Flash Players as of October 26 2014. Please help!

    The download link has moved since then: http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player.exe

  • Can't Install Flash Player, What does "Only a single instance of this application can run" mean?

    I try to follow the steps 1-3, as it shows. After it downloads, after step 2, a dialog box pops up saying “Open Executable File? Then it says it may contain viruses or malicious code and to be careful when opening file.  So I click OK, then step 3 occurs, file name lists as: install_flashplayer11x32_mssd_aih(2).exe.  So then I hit “Run”.  Then another dialog box pops up titling “UI_FlashPlayerInstaller”, and it says “Only a single instance of this application can run”, “OK”. I’ve checked to see if there is another version installed, but I don’t see any.  I am operating a Windows 32 Bit, FireFox,

    Download the full installer from this FAQ http://forums.adobe.com/thread/909550
    Save it to disk, then close all browser windows and run the downloaded installer.

  • Why I can't install adobe keep getting: "only a single instance of this application can run"?

    Hello, Can someone help me with Adobe Flash Player installation ?
    I have tried too many things to install it but keep getting this message " only a single  instance of this application can run. 
    I can't see any Adobe applications, I've tried deleting all files adobe and still nothing.
    I have opened the task manager and try to end the processes related to Adobe manually by selecting 'End Process' and then try to install it, but nothing happened.
    I've tried 'clean boot' but neither worked.I downloaded the 'Adobe unistaller' from the official page and the 'latest version of flash player' but it doesn't work!.
    I've also went on the Adobe website and it said this error message was due to the flash application but I deleted all of those files to and still nothing.
    I've got firefox and windows 7.

    If you haven't done so already, reboot your computer, then re-run the installer you downloaded.

  • Not able to install Adobe 17x32.Getting message  only a single instance of this application can run

    Sir,I can't install Adobe 17X32.I have      Win 7 system.All previous versions have been uninstalled and yet I am getting a message--ONLY A SINGLE INSTANCE OF THIS APPLICATION CAN RUN.How do I remedy the situation?
    Thanks,
    Message was edited by: Maria Vargas
    Removed personal email address, which should not be included in a public forum.

    Hi Viraj,
    Please try the offline installer posted at the bottom of the Installation problems | Flash Player | Windows page, in the 'Still having problems' section.
    Maria

Maybe you are looking for