Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Detecting whether the piece of code is executing?

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Detecting whether the piece of code is executing?

    Hi All

    I am working on a web application with struts 1.1 as framework and oracle as backend. In the application I have a requirement that I need to keep a particular piece of code executing all the time. In fact this code traverses all the records(orders) in the database. It cheks whether there are any new orders and then proceeds to fulfill them. I have created class file and put it in scheduler for execution through the Javac command through a batch file.

    Now I want to deploy it on web server. A web hosting space has been purchased for it. Its's a shared hosting. So now I have to detect whether the code is running or not. Previously I used to do this by using JPS command. If there were no processes in the RunTime then it was invokesd again. So even after exception occurs the code again can be executed by invoking the scheduler.

    Please help me in how can verify that a particular piece of code is being executed or not in a shared hosting environment.

    Thanks in advance
    Vivek


  2. #2

    Default Re: Detecting whether the piece of code is executing?

    I think you can use threads to perform that. And that thread can update a database or do anything to help you detecting its execution.

    You have to write two threads like those:

    public class SchedulerThread extends Thread {
     
    	private Long intervalTime = new Long("6000");
     
    	public SchedulerThread (Long intervalTime) {
    		super();
    		this.intervalTime = intervalTime;
    	}
     
    	public void run() {
    		while (true) {
    			PerformActionThread t = new PerformActionThread ();
    			t.start();
    			try {
    				Thread.sleep(intervalTime);
    			} catch (InterruptedException e) {
    			}
    		}
     
    	}
     
    }

    public class Temp extends Thread{
     
    	public void run() {
    		System.out.println(new Date());
                   // Here you will perform your action and update the database or something to check later  
    	}
    }

    The thread above will print the date every 6 seconds.

    And finally in one servlet that you will init with your web application you will start an SchedulerThread instance:

    SchedulerThread t = new SchedulerThread (new Long("5000"));
    t.start();

    Please tell me if you need more help with this.
    Last edited by leandro; March 9th, 2009 at 06:20 PM.

  3. #3

    Default Re: Detecting whether the piece of code is executing?

    Vivek did I help you with my post?

  4. #4
    Junior Member
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Detecting whether the piece of code is executing?

    Thanks sir. The problem is solved now....

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Detecting whether the piece of code is executing?

    Hello vivek1982,

    Did leandro solve your problem with his code above?

    If not, please post your solution. I'm sure it will help others in the future
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Detecting File Download Completion
    By fedfan in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: June 5th, 2009, 04:27 AM

Tags for this Thread