How to know if the java program is already running?

I have a simple java program, and I need some way to know if this program is already running. I need it because when I execute this program and during this execution I execute it again, two java programs are running in the Operating System. Is there any java method that tells if the current program is already running?

Hey, stevejluke and nicklap, do you know about Threads? I NEED SOME HELP, URGENTLY!!! I�ve posted the same problem two times in this forum, but nobody gave me the solution. It seems to be very simple, and I�m very angry because I am wasting a long time because this ridiculous problem. Read the text below please. If you know some suggestion or tip, tell me!
Sorry for posting this topic again. But I need some suggestion urgently. I put the last post below.
==============================
I�ve been trying to test my application in Eclipse, and I am using threads. But when I debug it, sometimes the behavior is not what I am expecting. Sometimes when I stop at some breakpoint for a long time, the debug stops to execute. Curiously the application runs perfectly in run mode.
Has anyone had this problem?
Thanks.
==============================
==============================
(m.winter)
Debugging threads works perfectly in eclipse. However be aware: If you just set a breakpoint by doubleclicking left to the source line, then its policy ist to stop the trhread, not the VM. That means, once you reach the breakpoint, only the thread reaching that line is stopped. All other threads continue running. If a second thread later also hits that line, it is also stopped. This makes it sometimes difficult to find out, where you are, as two or more threads may be suspended. You can see the status of the threads and switch between them in the treah view, typically in the upper half of the screen.
You can change the behaviour of a breakpoint to "suspend VM" by left-clicking on the breakpoint and choosing breakpoint properties.
I assume in your case, that other threads are continuing to run. They may e.g. produce data, which is supposed to be worked on by the suspended thread. If you stay a long time at the breakpoint, finally you might run out of memory or something else happens, which does not occur in run mode.
==============================
==============================
(Peter-Lawrey)
If you have anything in your code which is time depend it can run fine, except when you debug it.
e.g. if one thread times out because you have stopped another thread.
==============================
==============================
Thanx, but I didn�t understand yet.
Sorry if I commit any English language error, I�m learning English.
Please try to debug the code below:
public class Main {
    public static void main(String[] args) {
        Shared objShared = new Shared();
        Thread thread1 = new Thread(new Thread1(objShared));
        Thread thread2 = new Thread(new Thread2(objShared));
        thread1.start(); //put breakpoint here
        thread2.start();
class Thread1 implements Runnable {
    private Shared objShared;
    Thread1(Shared shared) {
        objShared = shared;
    public void run() {
        try {
            objShared.doSomething1();          
        } catch(InterruptedException e) {
            e.printStackTrace();
class Thread2 implements Runnable {
    private Shared objShared;
    Thread2(Shared shared) {
        objShared = shared;
    public void run() {
        try {
            objShared.doSomething2();          
        } catch(InterruptedException e) {
            e.printStackTrace();
class Shared {
    private boolean x = false;
    synchronized void doSomething1()
        throws InterruptedException {
        while (x) //put breakpoint here
            wait();
        System.out.println("Doing something 1");
        x = true;
        notifyAll();
    synchronized void doSomething2()
        throws InterruptedException {
        while (!x)
            wait();
        System.out.println("Doing something 2");
        x = false;
        notifyAll();
}"If you stay a long time at the breakpoint, finally you might run out of memory or something else happens" - I don�t wait a very long time. Just few seconds in the "while" breakpoint is enough to debug stops the execution.
"You can change the behaviour of a breakpoint to "suspend VM" - I did it, but in properties I didn�t find any thing to configure in order to debug perfectly.
In debug mode, when I press F6 button rapidly, this program is executed perfectly. The problem occurs only if the debug is stopped for few seconds in breakpoint. Try it, I�m really interested in the cause of this behaviour.
Thanks a lot!
==============================
I don�t know why does this behaviour occur! If anyone has the solution for my problem, please tell me!
**************************************************************************************************************************

Similar Messages

  • How to abend the java program -if the condition fails

    Hi
    My program counts the number of headers in the input file and if the condition fails to satisfy the number we expected , it should comeout of the java program . Is their a specific statement to abend the program in java .
    if(columnCount == 5)
    // do all the steps
    else
    //abend the program }
    how to do that .... is it System.exit(1) or anything else
    thanks..
    Edited by: 1sai on Apr 23, 2009 6:52 PM

    BigDaddyLoveHandles wrote:
    It must have been that the [card sorters|http://en.wikipedia.org/wiki/Card_sorter] were making such a ruckus that I didn't hear it. The model 84 -- 2,000 cards a minute? -- dämn, that's sweet.
    I remember the first time I saw a card sorter in action, thinking it was kind of cool.
    I also think the teacher used it to describe some sorting algorithm, maybe radix sort??
    You've got me thinking, that might be part of the problem with computing today, not enough moving parts. No big tape drives spinning and oscillating. And few if any line printers anymore. Now there's an interesting piece of equipment.

  • How to write the java program to retrieve the last 7 days dates

    Hi,
    I am having requirement that how to write the java program to retrieve the last 7 days dates. Please help me.
    Regards,
    Ahamad

    It needs any jar file.Of course!
    I did using jscape.My program is running fine.But it
    requires jar file.Which is licensed version.Maybe you should follow the link the the 'license' on the site I posted!
    >
    I have the doubt is apache provides jar file free
    versionMaybe you should follow the link the the 'license' on the site I posted!

  • How to invoke the .bat(batch file ) from the java program

    i want to run some commands when i run one java program.
    I wrote those dos commands on the batch file and i want to include the bat file in the java program so that i can execute the bat file when i run the java program.
    tell me the way that i can run my bat file inside the java program.

    i tried this :
    a .bat file named test.bat, with this code : copy test.bat test2.bat
    a java class, Test.class, in the same directory
    public class Test {
         public static void main(String[] args) {
              try {           
                   Runtime rt = Runtime.getRuntime();
                   Process proc = rt.exec("cmd /c test.bat");
                   proc.waitFor();
                   int exitVal = proc.exitValue();
                   System.out.println("Process exitValue: " + exitVal);
              catch (Throwable t) {
                   t.printStackTrace();
    }

  • Running the Java program as service.

    Hi,
    I want to create have java program, which runs continously. This would hit check a table in Database for any new records and if there is anything it would post a message to another service. It would keep track of how many messages were posted and how many were completed at any point of time.I should have the ability to stop this service. When a stop sequence is initiated, it should wait till all the messages are processed and shutdown. I am looking for inputs on how to invoke the java program as service and the second part (stopping the service). I dont want to Java wrapper service or commons daemon api. I am on JDK 1.4.2
    Thanks in Advance.
    Regards,
    Arul.

    Do you want to write a daemon? I dont think you can do it without some explicit OS support..
    Well, lemme know if you find a way

  • How to call stand Alone java program from jsp

    Hello all...
    I want to use the stand alone java program in jsp page. I compiled the java program and place the class file in classes folder under web-inf. But when i try to instantiate the java class inside jsp it is not recognizing the class. Where might be the problem
    Plz help....
    Shamim

    hi , this is dheeraj.. i need to know that how to execute java code and class in jsp.. if anyone know about if bt tell me.. i just know that we can use java code by java beans in jsp.. if you know any knowledge regarding this topic please send me.....

  • Is it possible to run the java program without main?

    Hi,
    Is it possible to run the java program without main?
    if anybody know please tell me, how it is possible.
    Regards,
    Ramya

    Hi,
    Is it possible to run the java program without main?
    if anybody know please tell me, how it is possible.
    Regards,
    RamyaWhy do you ask? It sounds like an odd question. Your program can be an applet and it doesn't need a main method in that case.
    Kaj

  • Fedora 13: After upgrading from FF3.6 to FF6.0.2 I no longer have a Java plugin. How do I configure the Java Plugin for FF 6 ? There is no Java Plugin at the site

    I am Fedora 13x64 bit. I just installed FF v6.0.2 from the FF download site. I backed up the existing FF 3.6 as firefox_old
    I need to have a Java plugin to access company site, how do I configure the Java Plugin ?
    At the Plugin area in FF6 there is no Java Plugin available, even after a search.
    I have Java 1.6.0 installed in the OS at:
    /usr/lib/jvm/java-1.6.0/jre/lib/amd64/libnpjp2.so
    I googled how to configure Java Plugin for FF 6 for Fedora 13 and the trick was to create a soft link from /home/<userID>/.mozilla/plugins to the above libnpjp2.so

    AVtech wrote:
    . . . If a person can't get an answer here I don't know where else to turn since Sun certainly wouldn't offer tech support for a free product . . .These forums are user forums, and only occasionally visited by Sun employees. Sun does provide Java technical support options, although (of course) at a charge.
    See:
    http://developers.sun.com/services/
    . . . I guess we'll just use JRE 5 until it's unsupported, whenever that will be. I'm still waiting for an answer on that question, too. See:
    http://java.sun.com/products/archive/eol.policy.html
    http://www.sun.com/service/eosl/
    This document (part IV and Appendix) has some debugging and troubleshooting information that may allow someone involved in the problem to resolve the cause:
    See:
    http://java.sun.com/javase/6/docs/technotes/guides/plugin/developer_guide/contents.htm
    Any steps that you can take to isolate the problem to specific Java versions, browsers, applets, web sites, operating systems (and versions), etc, would enhance the possibility of getting help.
    You can try the applets at this Sun location and see if any of them are "slow".
    See:
    http://java.sun.com/javase/6/docs/technotes/samples/demos.html

  • How can you get a java program working on a cell phone?

    I was thinking of making some stuff for cell phones so i was wondering how you get a normal java program to work on cells.

    its all j2me - midlet package....Huh? The jsr-118 MID profile alone has 11 packages, one of which is javax.microedition.midlet. Notj2me - midlet.
    works best on nokia phones.Sez who? You seem to be confusing Java ME with Symbian C.
    you can use net beans midlet packge add-on.Only it's called the NetBeans Mobiliity Pack.
    Its easy to use and has lots of tutorials.Ditto for the Wireless toolkit for CLDC.
    just search on google.Yes, but with which keywords?
    @OP:
    NetBeans mobility pack comes with a short tutorial and several samples, you also need to download the latest WTK as the ver. 2.2 which comes bundled with NetBeans is just too buggy to work with. Then there are the manufacturer-specific SDKs from Nokia, Motorola, Sony Ericsson and (maybe) others.
    If and when you get started in Java ME aka j2me, it will be appropriate to post any questions you might have on the mobility forums, not here.
    Google "j2me tutorial" for many good hits.
    luck, db

  • How do I enable the Java Accessibilty Stuff?

    Hi. I'm trying to make my application accessible via a screen reader to impaired users. Unfortunately, I'm not having any success whatsoever. If I didnt know Java had accessibility stuff built-in, I would assume that it was just not compatible at all with screen reader technology.
    How do I enable the Java accessibility stuff so that UI components are accessible to a screen reader; they can be iterated over and get sensible names and/or descriptions of them?
    I wrote a simple application, attached below, which just makes a demo UI from which I can start learning the basics of the accessibility stuff. Out of the box, the UI is completely opaque to a screen reader (I'm using the VoiceOver utility bundled with Mac OS X, which does ok with normal applications).
    I tried setting things focusable to no avail, voice over cant cycle through the UI component using the normal keyboard short cuts, and nothing is spoken when I tab between components, despite some things having natural labels, like a menu, and some things, like the button, where i've set the accessible name and description on the accessible context of the component.
    Obviously, I'm doing something wrong or I just don't understand how the accessibility stuff works.
    Could someone please shed some light on this so that I can make my application accessible to a screen reader?
    Thanks.
        private static void try508Example() {
            JFrame aFrame = new JFrame();
            JMenuBar aMenuBar = new JMenuBar();
            JMenu aMenu = new JMenu("Test");
            aMenu.setMnemonic(KeyEvent.VK_T);
            JMenuItem aItem1 = new JMenuItem("Test Item 1");
            aItem1.setFocusable(true);
            aItem1.getAccessibleContext().setAccessibleName("Test Item 1");
            aItem1.getAccessibleContext().setAccessibleDescription("Test Item 1 Description");
            JMenuItem aItem2 = new JMenuItem("Test Item 2");
            JMenuItem aItem3 = new JMenuItem("Test Item 3");
            aMenu.add(aItem1);
            aMenu.add(aItem2);
            aMenu.add(aItem3);
            aMenuBar.add(aMenu);
            aFrame.setJMenuBar(aMenuBar);
            JTabbedPane aTabPanel = new JTabbedPane();
            aTabPanel.setFocusable(true);
            JTextArea aTab1Comp = new JTextArea();
            JScrollPane aTab2Comp = new JScrollPane(new JTree());
            aTabPanel.addTab("Tab1", aTab1Comp);
            aTabPanel.addTab("Tab2", aTab2Comp);
            JTree aTree = new JTree();
            aTree.setFocusable(true);
            JLabel aLabel = new JLabel("some label");
            aLabel.setLabelFor(aTree);
            aLabel.setFocusable(true);
            JScrollPane aScrollList = new JScrollPane(new JList());
            aScrollList.setFocusable(true);
            JButton aBtn = new JButton("Button");
            aBtn.setFocusable(true);
            aBtn.getAccessibleContext().setAccessibleName("Button Name");
            aBtn.getAccessibleContext().setAccessibleDescription("Button Description");
            JPanel aContent = new JPanel(new BorderLayout());
            aContent.add(aTabPanel);
            aContent.add(aBtn, BorderLayout.NORTH);
            aContent.add(aScrollList, BorderLayout.EAST);
            aContent.add(aTree, BorderLayout.WEST);
            aContent.add(aLabel, BorderLayout.SOUTH);
            aFrame.setContentPane(aContent);
            aFrame.setSize(640, 480);
            aFrame.setVisible(true);
            aFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        }

    Ok, so a very curious issue. If I comment out adding the menu bar to the window, ie comment out this line:
    aFrame.setJMenuBar(aMenuBar);
    The screen reader reads me back everything just like I would expect. I comment the line back in, and nothing, the application is completely invisible to the screen reader.
    Anyone have any idea what this is about?

  • How can i  apply this  java program for  a jsp page?

    import java.io.*;
    import java.util.*;
    public class FileProcessing
      //create a vector container  for the input variables
         Vector variables = new Vector();
      //create a vector container for the constants
         Vector constants = new Vector();
      /*create a string expression container for the equation
         as read from the file */
         String expression = " ";
      //create double result container for the final result
         double result = 0;
         public boolean processFile(String filename,String delim)
          //index for values vector
              int num_values = 0;
          //index for constants vector
              int num_constants = 0;
          //current line being read from the external file.
              String curline = " ";
          //start reading from the external file
              try
                   FileReader fr = new FileReader(filename);
                   BufferedReader br = new BufferedReader(fr);
                   while(true)
                        curline = br.readLine();
                        if(curline == null)
                             break;
                    //determine the type of current interaction
                        boolean variable = curline.startsWith("input");
                        boolean constant = curline.startsWith("constant");
                        boolean equation = curline.startsWith("equation");
                        boolean output = curline.startsWith("result");
                   //on input variables
                        if(variable)
                          StringTokenizer st = new StringTokenizer(curline,delim);
                          int num = st.countTokens();
                          int count=0;
                          while(st.hasMoreTokens())
                               String temp = st.nextToken();
                               if(count==1)
                                    byte b[]= new byte[100];
                                    System.out.println(temp);
                                    System.in.read(b);
                                    String inputval = (new String(b)).trim();
                                    variables.add(num_values,inputval);
                                    num_values++;
                               count++;
                        // on constant values
                        if(constant)
                             StringTokenizer st = new StringTokenizer(curline,delim);
                             int num = st.countTokens();
                             int count = 0;
                             while(st.hasMoreTokens())
                                  String temp = st.nextToken();
                                  if(count==1)
                                       byte b[]= new byte[100];
                                       System.out.println(temp);
                                       System.in.read(b);
                                       String cons = (new String(b)).trim();
                                       constants.add(num_constants,cons);
                                       num_constants++;
                                  count++;
                        // on equation
                        if(equation)
                             StringTokenizer st = new StringTokenizer(curline,delim);
                             int num = st.countTokens();
                             int count = 0;
                             while(st.hasMoreTokens())
                                  String temp = st.nextToken();
                                  if(count==2)
                                       this.expression = temp;
                                  count++;
              // now we are ready to evaluate the expression
                       if(output)
                          org.nfunk.jep.JEP  myparser= new org.nfunk.jep.JEP();
                          myparser.setAllowAssignment(true);
                          for(int i=1;i<variables.size()+1;i++)
                             String name = "arg"+Integer.toString(i);
                             myparser.addVariable(name,new Double(variables.get(i-1)
                                                .toString()).doubleValue());
                          for(int i=1;i<constants.size()+1;i++)
                               String name = "arg" +Integer.
                                         toString(i+variables.size());
                               myparser.addConstant(name,new Double(constants.get(i-1).toString()));
                   //output is obtained as follows
                          myparser.parseExpression(expression);
                          result = myparser.getValue();
                          System.out.println("Assay value: "+result);
              catch(Exception e)
                   System.out.println(e.toString());
              return true;
         public static void main(String[] args)
              FileProcessing fp = new FileProcessing();
              fp.processFile("input.eqn",":");
    }//my text file name is: "input.eqn" (given below)
    input:Enter Value1:arg1
    input:Enter Value2:arg2
    input:Enter Value3:arg3
    constant:arg4
    constant:arg5
    Equation:arg1+arg2+arg3
    result:

    how can i apply this java program for a jsp pagewhy do you want to do this ?
    Your program reads from a file on the disk and formats based on a patterm.
    Jsp is not intended for such stuff.
    ram.

  • How to know whether the javascript is disabled or not while loading the jsp

    Hi,
    My query is like how to know whether the javascript is disabled or not while loading the Application main JSP in Mozilla browser.
    I want some Java code or JavaScript code.

    To the point, just let JS fire a specific HTTP request inside the same session.
    This can be done in several ways. 1) Create a hidden <img> element and set the `src` attribute so that it will request a (fake) image from the server. The server just have to intercept on this specific request. 2) Fire an ajaxical request and let the server intercept on it. You can use a Filter for this which sets a token in the session scope to inform that the client has JS enabled.

  • How to know whether a concurrent program (report, procedure) is ......

    Hi All,
    How to know whther a conurrent program (report or package) is "Single OU or Multiple OU".
    OU: Operating Unit
    Any advice appreciated.
    Thanks

    Are you asking how to tell whether a concurrent program can be run for a single Operating Unit in a multi-Operating Unit environment?
    If you are asking about standard Oracle concurrent programs, then I would say that they should all be capable of running for a single OU in a multi-OU environment WHERE the module relates to operating units. For example the HR/Payroll modules do not relate to operating units, but rather business groups and concurrent programs in these modules will be able to be run by business group.
    If you are asking about custom concurrent programs, then I would suggest the easiest way to tell would be to run them and see, although having an Org ID parameter would be a good indication.

  • How communion between trigger and java program?

    I want to achieve the effect:when data in database change ,the java program can know,but don't use refresh method?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Jerry wang ([email protected]):
    I want to achieve the effect:when data in database change ,the java program can know,but don't use refresh method?<HR></BLOCKQUOTE>
    You can achieve that effect with oracle alert package.
    Victor Batista
    null

  • How can I uninstall the cc programs I don't use without uninstalling the ones I need and the cs6 versions?

    How can I uninstall the cc programs I don't use without uninstalling the ones I need and the cs6 versions?

    Creative Cloud Help | Install, update, or uninstall apps is the official Adobe link... I do NOT know if you may select individual programs

Maybe you are looking for

  • Unable to create delivery

    hi i have stock alot of stock, and my order is fully ready no issue with schedule lines or stock in the order, but when i try and create a delivery its saying that one item doesnt get copied in my delivery saying the following only 0.00 PAL OF MATERI

  • Saving app data on mobile devices?

    Hey, I want to make a save file for the game I'm making for iOS and Android, but I'm not sure how to go about doing it. Should I make a text file? Where do I store it/read it from? Where does it go? Any help would be greatly appreciated. -Thanks in a

  • My iTunes won't connect to Internet

    Microsoft Windows 7 x64 Home Premium Edition Service Pack 1 (Build 7601) Gigabyte Technology Co., Ltd. To be filled by O.E.M. iTunes 11.1.1.11 QuickTime not available FairPlay 2.5.16 Apple Application Support 2.3.6 iPod Updater Library 11.1f5 CD Driv

  • Homogeneous System Copy of ABAP+JAVA Sy - sapinst does not restart after re

    Hi everybody! Someone can help me? I am doing system copy CRM 2007 (NW 7) from DEV to Sandbox system. after database recovery sap is unable to make connection to database (DB is up and running). R3trans -d finished with 0012. My question is how to ch

  • So how do I resolve this stupid declined card iTunes's stuff?

    Please tell me how to log into my App Store again. I keep getting the declined card message and I have 6 apps that are messing up because they aren't updated