Make java program run on a scheduler

I have a java program that currently runs as a cron job at specific intervals. I want to run it at smaller intervals not allowed by cron, like every minute. I want it to wake up, check it's work load, process it, and then sleep for a minute...and do this over and over again. What code can I insert into my java program to accomplish this.

All you need is to have all of your Threads go back to sleep when there is no work to be done so that your application doesn't consume any resources while it doesn't have any work to do.
If you want your application to go back to sleep for one minute when it has emptied a JobQueue, all you need is to use Thread.sleep(60000); inside the piece of code which is looking for the work load.
Overall, this approach is much better than a cron job, since you could end up with concurrency issues with the cron job. Consider ending up with a workload which requires more than a minute to be processed... Before you can get it done, there's a new instance of your program which tries to get the same jobs done at the same time! You could get a lot of headaches with this :P
Message was edited by:
Dalzhim

Similar Messages

  • Make Java program run on other pc's

    Good afternoon,
    So I have this Java program compiling on my pc through NetBeans.
    Now if I want this program to run on other pc's on its own (without NetBeans or any other program), preferably through a GUI, do I have to convert it to a JAR file? How does this exactly works out?
    Thanks for your help.

    alley wrote:
    So I have this Java program compiling on my pc through NetBeans.And Netbeans does it using the JDK. it is always the JDK, no matter how many tools you wrap around it on top. You don't need Netbeans to run your stuff either, it is merely a development convenience that Netbeans provides you.
    >
    Now if I want this program to run on other pc's on its own (without NetBeans or any other program)Impossible - you need at least a compatible Java runtime.
    , preferably through a GUIYou mean by double clicking on the program icon through the OS?
    , do I have to convert it to a JAR file? That would be an easy way yes - an executable jar to be more precise
    How does this exactly works out?Netbeans builds the jar automatically, just check out the folders of your project to find it. If you set a main class in the project properties, it is even an executable jar. Double click it and if the Java runtime is properly setup (which tends to be the case when it installs succesfully, but many people manage to screw it up in a way I can't imagine anyway), it will run.
    For further guidance, check the online netbeans manual and research executable jars.

  • Execute Unix command from Java program running on windows

    Hello,
    I need to write a java program that fetches file count in a particular unix machine directory. But java program will be running on windows machine.
    The program should execute unix list command and fetch the output of that command.
    Can anyone help me on this?
    Thanks.

    Hi there,
    I had a similiar problem, though years ago. It was to have a java program execute any other. Lately, I've had to have a java program running on a unix machine execute a shell script. Entirely two different scenarios. I'm not sure what you will need for your app, but look into this:
    Java Native Interface for executing C/C++ code.
    C/C++ Code for launching the program you need to run.
    java.lang.Runtime(?).exec(....)
    With a combination of that stuff, you can make a launcher for any os that has Java running on it, and with Runtime, you can exec() pretty near any sort of unix shell or app command you'd like.
    Good luck.
    Tim

  • Is there any way to check another Java program running status?

    HI. I want to write a Java program on hand-set but my program seems needs lots of resources and if there is another Java program running on the same hand-set simultaneously, my program will slow down. So, I want to check if there is another Java program is running on the hand-set, my program will show a message to user reminding user to close another program first.
    Is there any way to do so?

    On most recent devices, the application is not terminated but paused by using phone functions, and can be reactivated from the aplication management software. The javax.microedition.midlet package documentation is quite specific, if a tad obscure, about the MIDlet lifecycle and the role of the MIDelt methods vis-a-vis the AMS.
    {color:#0000ff}http://java.sun.com/javame/reference/apis/jsr037/javax/microedition/midlet/package-summary.html{color}
    Parenthetically, I've never been able to figure out how resumeApp should be used, nor have I seen this method invoked in any of the samples that come with the WTK, but I haven't gone through all of them.
    I believe the still-in-progress MIDP3 will make it possible to have MIDlets that share the screen with native apps and which can be minimized and restored.
    db

  • Process name representation in a LINUX machine for a JAVA program running..

    Hi,
    We are using an Intel machine loaded with Red Hat Linux 7.2 OS to run JAVA programs. We have a requirement to calculate the CPU and MEMORY usage for each JAVA program running. Unfortunately when a java program is run say "java ESR" and we run a ps -ef | grep -i java, it is shown as hkumar 2847 2799 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2874 2847 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2875 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2876 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2877 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2878 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2879 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2880 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2881 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2882 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2883 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2884 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    hkumar 2885 2874 0 19:15 pts/3 00:00:00 /usr/java/jdk1.3.1_03/bin/i386/n
    instead of the actual name of the program ie. ESR.
    Does anybody know why this happens? Is there a way out to ensure that "ps -ef | grep java" gives the actual name of the java program being RUN?
    Thanks in advance,
    Harish

    You have less chance to identify which programm that VM instance is running right now.
    But you could (as we do) keep track of your programs if you save the process-id when you start the program.
    We need this to shut down running java batch programs but you could find out the used system resources with this way as well...

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • My java program runs fine even if i don't specify access specifier of class

    Hi,
    My java program runs fine even if i don't specify access specifier of class as public .
    Then why do they say that atleast one class should be specified as public.
    please help.

    public access specifier is the default access
    specifier
    so if you dont give the access specifier before the
    class name it is not wrong.I think that you are wrong. The default specifier is package or "package-private".
    See here:
    http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
    Message was edited by:
    petes1234

  • How to make a java program run as a background process.

    </pre>
    writing a client server application.
    a program is supposed to run on a the client right from the time the client turns on the computer till the computer is turned off.
    the catch is the client should all the time be unaware of the program running in his computer, no dos prompt window, no icon on the taskbar,etc. can i convert it the class file into an exe file through software and put the exe filename in autoexec.bat. But then i think that the dosprompt window will open up on starting, but the client should see nothing.
    please help
    </pre>

    </pre>
    Thanks Daniel and jesper,
    could not really fully understand what you mean.
    creating a batch file is okay, but do you configure it
    to run in a an hidden mode.
    Also I have no idea of how to make a window
    service.can you please elaborate a bit
    </pre>

  • How to make a program run in background?

    Is there any ways to make an invisible program with java? a program that is running in background but the user cannot see it and it's not in the Start bar and the user cannot close it.

    There are also 3rd party software that lets you install a java program as a service in winnt/2k/xp so that you can start/stop it from the service manager, doesnt even matter if the java program is gui based or not, as there are options (in win2k at least) in the service manager that allows the program to interact (think show gui) or not...one software called JNT comes to mind..
    Anyway, if you're using win98/me equivalent, then just use javaw.exe like suggested by previous posters.

  • Make the program run again, given the user's input?

    Hello,
    I need a little help with this program, you can see the entire thing below. I'm trying to make the program give the user the option to run again, using y or n. It's for a college project. Thanks.
    import java.util.*;
    class MyFifthProgram
         public static void main (String[] args)
              //char letterOnTelephone;
              do
                   System.out.print("Enter a letter from A - Z and I will output the corresponding number \non the telephone, then press enter:");
                   Scanner keyboard = new Scanner(System.in);
                   String letterOnTelephone = keyboard.next();
                   char letter = letterOnTelephone.charAt(0);
                   switch (letter)
                        case 'Q':
                        case 'q':
                        case 'Z':
                        case 'z':
                             System.out.println("Sorry, the letter " + letterOnTelephone + " cannot be found on the telephone....");
                             break;
                        default:
                             System.out.println("Sorry, the key " + letterOnTelephone + " cannot be found on the telephone......");
                             break;     
                        case 'A':
                        case 'a':
                        case 'B':
                        case 'b':
                        case 'C':
                        case 'c':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 2.");
                             break;
                        case 'D':
                        case 'd':
                        case 'E':
                        case 'e':
                        case 'F':
                        case 'f':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 3.");
                             break;
                        case 'G':
                        case 'g':
                        case 'H':
                        case 'h':
                        case 'I':
                        case 'i':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 4.");
                             break;
                        case 'J':
                        case 'j':
                        case 'K':
                        case 'k':
                        case 'L':
                        case 'l':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 5.");
                             break;
                        case 'M':
                        case 'm':
                        case 'N':
                        case 'n':
                        case 'O':
                        case 'o':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 6.");
                             break;
                        case 'P':
                        case 'p':
                        case 'R':
                        case 'r':
                        case 'S':
                        case 's':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 7.");
                             break;
                        case 'T':
                        case 't':
                        case 'U':
                        case 'u':
                        case 'V':
                        case 'v':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 8.");
                             break;
                        case 'W':
                        case 'w':
                        case 'X':
                        case 'x':
                        case 'Y':
                        case 'y':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 9.");
                             break;                                             
                   System.out.println("Would you like to run this program again? Enter Y for yes, or N for no:");
                   Scanner keyboard1 = new Scanner(System.in);
                   String runAgain = keyboard1.next();
                   char runIt = runAgain.charAt(0);
                   }while (runIt == 'y');
                        System.out.println("You can choosen " + runAgain + " therefor the program will run again.");
         }

    Thanks! That did the trick, however that doesn't solve my problem. How do I ask the user to run the program again at the end of the program? What am I missing?
    // Program takes a single letter and displays the corresponding digit on the telephone.
    import java.util.*;
    class MyFifthProgram
         public static void main (String[] args)
              System.out.println("Would you like to run this program? Enter Y for yes, or N for no:");
              Scanner keyboard1 = new Scanner(System.in);
              String runAgain = keyboard1.next();
              char runIt = runAgain.charAt(0);
              if (runIt == 'n')
                   System.exit(0);
              else if (runIt == 'N')
                   System.exit(0);
              do
                   System.out.print("Enter a letter from A - Z and I will output the corresponding number \non the telephone, then press enter:");
                   Scanner keyboard = new Scanner(System.in);
                   String letterOnTelephone = keyboard.next();
                   char letter = letterOnTelephone.charAt(0);
                   switch (letter)
                        case 'Q':
                        case 'q':
                        case 'Z':
                        case 'z':
                             System.out.println("Sorry, the letter " + letterOnTelephone + " cannot be found on the telephone....");
                             break;
                        default:
                             System.out.println("Sorry, the key " + letterOnTelephone + " cannot be found on the telephone......");
                             break;     
                        case 'A':
                        case 'a':
                        case 'B':
                        case 'b':
                        case 'C':
                        case 'c':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 2.");
                             break;
                        case 'D':
                        case 'd':
                        case 'E':
                        case 'e':
                        case 'F':
                        case 'f':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 3.");
                             break;
                        case 'G':
                        case 'g':
                        case 'H':
                        case 'h':
                        case 'I':
                        case 'i':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 4.");
                             break;
                        case 'J':
                        case 'j':
                        case 'K':
                        case 'k':
                        case 'L':
                        case 'l':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 5.");
                             break;
                        case 'M':
                        case 'm':
                        case 'N':
                        case 'n':
                        case 'O':
                        case 'o':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 6.");
                             break;
                        case 'P':
                        case 'p':
                        case 'R':
                        case 'r':
                        case 'S':
                        case 's':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 7.");
                             break;
                        case 'T':
                        case 't':
                        case 'U':
                        case 'u':
                        case 'V':
                        case 'v':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 8.");
                             break;
                        case 'W':
                        case 'w':
                        case 'X':
                        case 'x':
                        case 'Y':
                        case 'y':
                             System.out.println("The letter " + letterOnTelephone + " corresponds to the number 9.");
                             break;                                             
                   }while (runIt == 'n');
              //          System.out.println("Would you like to run this program? Enter Y for yes, or N for no:");
              //          Scanner keyboard2 = new Scanner(System.in);
              //          String runAgain1 = keyboard2.next();
              //          char runIt1 = runAgain1.charAt(0);
              //          if (runIt1 == 'n')
              //               System.exit(0);
              //          else if (runIt1 == 'N');
              //               System.exit(0);
         }

  • Making a Java Program run by itself

    Hi all I was wondering if there is anyway for me to make my game run by itself without using my java compiler bluej.
    Here is some information on my program I think will be helpful
    Its a Class
    I save highscores to a notepad file
    I use a lot of images
    I have audio within it
    I also have classes out side of it that runs inside of it like Emeny, Item
    Edited by: Quickfingers90 on Jun 11, 2009 4:21 AM

    Quickfingers90 wrote:
    I used Bluej to make my jar file from my message from above could someone post the code in a very simple format that any programmer can understand it.What are you asking? How to deploy your application in a JAR? [http://java.sun.com/docs/books/tutorial/deployment/jar/index.html]
    edit: I don't know if you've heard of idea, but many people in this forum swear by it: start simple and do things one step at a time. For example:
    Doing something new like JARring an application?
    Start with a "hello world"-type program. You may not have a console window when running the JAR, so you should write to a file, or use a JOptionPane.
    Try accessing a resource, like an image or sound file zipped in the JAR. Hint: don't use file paths or File objects -- the resource is part of a JAR, now. See:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource]

  • Java program run as minimized

    hi all.
    how can i make my java program to run as minimized on systray?
    im using jdic tray.
    thanks.

    https://jdic.dev.java.net/nonav/documentation/javadoc/tray/index.html
    SystemTray.getDefaultSystemTray().addTrayIcon(new TrayIcon(new ImageIcon("imagefilename")))
    Or have you read the api and tried some code and are having a specific problem?

  • Why won't my program run when I schedule it.

    I am trying to schedule an executable and it says it is successful, but the program never runs.  I even tried setting up a simple batch file that will call the program and when I schedule it it says successful but never runs. When I run it on the desktop of the server it runs fine and the batch job runs fine.  I have tried configuring it several different ways and adding supporting files.  I have never scheduled a program in this application, so I'm sure I'm just missing something.  Can someone please tell me how to set this up or give me an example.  It is driving me crazy.

    1. Reset iPad
    2. Change the USB cable
    3. Try another charger

  • Java program running as win32-service

    Hi,
    I am running Java programs as Win32-Services on a Windows-Cluster with Windows 2000 Service Pack 4. I have written a Wrapper program in C which runs as a Service and creates a JVM. Normally this works fine but now I have on one cluster the problem that I don't have any output in the Console of the Service. All the output which is written with System.out.println to the console just does not appear.
    And if I read input from the console I get the following exception:
    -E-2005-02-15 16:04:44.734: java.io.IOException: The handle is invalid
    at java.io.FileInputStream.readBytes(Native Method)
    at java.io.FileInputStream.read(FileInputStream.java:194)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:220)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
    at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:408)
    at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:450)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at java.io.BufferedReader.fill(BufferedReader.java:136)
    at java.io.BufferedReader.readLine(BufferedReader.java:299)
    at java.io.BufferedReader.readLine(BufferedReader.java:362)
    at at.co.systema.gf.util.ConsolePrompt$ConsoleTask.run(ConsolePrompt.java:98
    Does anybody have experience with running java programs as Win32 services ?
    Ingo

    Your application needs to be able to run without System.in or System.out
    There is no console for a service.
    Replace System.out with a logger. If you need input you need to write a client which sends the commands to the service.

  • Can a java program run as a system process?

    Hi,
    I need to know if a java program can be run as a system process. I don't want it to be run as a user process. Is there any way at all?

    Tomcat is such a program.
    If you want to write a program that runs like a daemon (Unix) or a Windows service (Windows), use the Jakarta Daemon Framework (no, it is not an Indonesian devil) that was used to write Tomcat. Check http://jakarta.apache.org/commons/daemon/

Maybe you are looking for

  • ORA-01122: database file 8 failed verification check

    trc file: "dev_w0", trc level: 1, release: "700" *  ACTIVE TRACE LEVEL           1 *  ACTIVE TRACE COMPONENTS      all, MJ B  B Tue Apr 29 17:57:51 2014 B  create_con (con_name=R/3) B  Loading DB library 'D:\usr\sap\DEV\DVEBMGS00\exe\dboraslib.dll' .

  • How many times can I watch a purchased movie?

    Dear community, I just downloaded a movie via the iTunes store and I watched it successfully. At my second try to watch it again, I received a message saying: "You can't watch this movie on this PC." Anyone had this issue too?  I'm using iTunes 10.4

  • Fontproblem since CS5

    Hello, we are using Illustrator CS5 since a few weeks and we had a huge problem with the font Arial Unicode MS. Cyrillic words are cutted not normaly, so we had big mistakes in our designs. Before we upgrade to CS5 we use CS3 and it worked perfect wi

  • MSE Not Showing Clients After Upgrade to 7.6.100.0

    I've upgraded our 5508 WLC's to ver 7.6.100.0.  I've also upgraded our NCS to 2.0, and our MSE to 7.6.100.0.  I now can no longer see clients on the MSE map for our sites.  I've added the WLC to the MSE syncronization.  When I select "show clients" i

  • Precompiling JSPs using ant

    Hi Does anyone know a documented way to precompile a JSP using an ant script. I've tried a lot, but didn't find a satisfying solution. The best solution I've found was calling OJSPC from commandline via ants "java" task, but even this solution does n