Run method on spesific interval

I want to run a method in JSP page on spesific interval, after JSP is loaded in the browser.
How can I achieve this?

That really depends.
Do you want to run the events on the client? Using javascript? Does the information that the event handles change on the server side? Or is it just some predictable sequence (like a clock) that will be known without continuous contact with the server?
Do you want to run the events on the Server? Are the events supposed to interact with the client? Change what it displays? Get information from the client?

Similar Messages

  • How can I kill all Threads of the same class from within the run() method?

    Ok
    I have a class called Consumer that extends Thread
    I have several Consumer threans running... but, when a certain condition is true (within the run() method) in ANY of the threads, I want to kill ALL the threads of that object.
    is this possible?

    I know this is gonna be too demanding, but can someone please tell me why my Consumer's run() method never reaches the System.out.println( "ALL CONSUMING DONE") line
    Create a multi-threaded prime number calculator that is based on the producer-consumer model
    using semaphores. Your program should be able to check for prime numbers in a range specified
    by the user and with a variable number of threads. Example:
    $ java PrimeFind 3 5000 10000
    should use 1 producer and 2 consumers (3 threads in total, obviously the minimum is 2) to find all
    the prime numbers in the range [5000,10000].
    The producer should: use a buffer to store candidate numbers that have to be checked for
    primality.
    Consumers should: read from the buffer, check if a number is prime and update the status of the
    program accordingly (e.g. show the number on the screen, or save it to a file)
    import java.util.concurrent.Semaphore;
    import java.io.*;
    public class Assign1 {
    static int fromThisNumber;
    static int toThisNumber;
    static int numberOfThreads;
    static int buffer[];
    static Semaphore ready;          /*This semaphore is used by the Producer to signal
                                         an "OK" to the consumers*/
    static Semaphore critical;  /*This is a Mutex semaphore. It allows only 1 consumer
                                         to enter his critical section.
    static Semaphore counter;     /*This semaphore acts as a counter.
                                        Instead of having a global variable
                                         incremented each time, we just release()
                                         this semephore when we find a prime number
                                         Because remember that release() increments permits
    static Producer prod;
    static Consumer cons[];
    static int in=0;
    static int out=0;
    static PrintWriter outFile;
         public static void main (String args[]){
              try{
                   outFile=new PrintWriter(new FileWriter("primes.txt"));
                   }catch(Exception e){}
              numberOfThreads=Integer.parseInt(args[0]);
              fromThisNumber=Integer.parseInt(args[1]);
              toThisNumber=Integer.parseInt(args[2]);
              buffer=new int[Integer.parseInt(args[2])-Integer.parseInt(args[1])+1];
              ready=new Semaphore(0,false); /*We initialise it to 0 because we wait
                                                      for the Producer to produce atleast a
                                                      item. Suppose ready was 1 and if
                                                      Consumer ran first he would be in an
                                                      empty buffer */
              critical=new Semaphore (1,false);/*We initialise it to 1 because when
                                                         the first Consumer thread tries
                                                         to enter its critical section, it
                                                         should be allowed to;
                                                         Subsequent threads will have to
                                                         wait since only 1 thread can
                                                         access its critical section at a time*/
              counter=new Semaphore(0,false); // duh!
              cons=new Consumer[numberOfThreads-1]; /*numberOfThreads-1 because 1 thread
                                                                is taken by the Producer*/
              //Creating Producer object
              prod=new Producer();
              //Creating the Consumer object and start the thread.
              for(int i=0;i<cons.length;i++)
                        cons=new Consumer();
                        cons[i].start();
              prod.start();          
              //Printing to screen and file
    /*          for(int i=0;i<buffer.length;i++)
                   if(buffer[i]!=0)
                             System.out.println(buffer[i]);
                             outFile.println(buffer[i]);
              System.out.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits()+"\n primes.txt written");
              outFile.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits());
              outFile.close();*/                    
    static class Producer extends Thread {
         public void run(){try{
              while(in<buffer.length)     /*'in' should always be more than 'out'.Oherwise the consumer will try to access an empty index*/
                   {     System.out.println("producing");     
                        buffer[in]=fromThisNumber;
                        in++;
                        fromThisNumber++;
                        ready.release();
              catch (Exception e){e.printStackTrace();}
              System.out.println("ALL PRODUCING DONE");
    static class Consumer extends Thread {
         int tempout=0;
         public void run(){try{
              System.out.println("before while"+this.getId());
              while(tempout<=in)
                   System.out.println("before ready"+this.getId()+" "+ready.availablePermits()+" "+in);
                   ready.acquire();
                   System.out.println("before critical.acquire"+this.getId());
                   critical.acquire();
                   tempout=out;
                   out++;
                   critical.release();               
                   if(!isPrime(buffer[tempout]))
                        {System.out.println(buffer[tempout]+" by "+this.getId());buffer[tempout]=0;}
                   else {counter.release();System.out.println("prime added: "+buffer[tempout]+" by "+this.getId());}
                   critical.acquire();
                   tempout=out;
                   System.out.println("tempout:"+tempout+" of "+this.getId());
                   critical.release();
              System.out.println("ALL CONSUMING DONE"+this.getId());
         catch(Exception e){e.printStackTrace();}
         //Prime number-checking method     
         public boolean isPrime(int n){
              for(int i=2;i<=(n/2);i++)
                   if(n%i==0)
                        return false;
              return true;
    ======================
    import java.util.concurrent.Semaphore;
    import java.io.*;
    /* 3 questions to ask Barlas
    * Why error if I start the Consumer threads before Producer
    * Why does the counter semaphore always give a +1 result at the end
    * Is there a way I can verify that all the work is not being done by only 1 consumer thread? In other words, the workload is being shared properly
    * if I put ready.acquire() outside or inside the while loop, its not making any difference, why?
    * Strangely, its not making any difference if I playing with the release() and aquire() of the semaphores, WHY?!?!
    public class Assign1 {
    static int fromThisNumber;
    static int toThisNumber;
    static int numberOfThreads;
    static int buffer[];
    static Semaphore ready;          /*This semaphore is used by the Producer to signal
                                       an "OK" to the consumers*/
    static Semaphore critical; /*This is a Mutex semaphore. It allows only 1 consumer
                                       to enter his critical section.
    static Semaphore counter;     /*This semaphore acts as a counter.
                                  Instead of having a global variable
                                       incremented each time, we just release()
                                       this semephore when we find a prime number
                                       Because remember that release() increments permits
    static Producer prod;
    static Consumer cons[];
    static int in=0;
    static int out=0;
    static PrintWriter outFile;
         public static void main (String args[]){
              try{
                   outFile=new PrintWriter(new FileWriter("primes.txt"));
                   }catch(Exception e){}
              numberOfThreads=Integer.parseInt(args[0]);
              fromThisNumber=Integer.parseInt(args[1]);
              toThisNumber=Integer.parseInt(args[2]);
              buffer=new int[Integer.parseInt(args[2])-Integer.parseInt(args[1])+1];
              ready=new Semaphore(0,false); /*We initialise it to 0 because we wait
                                                      for the Producer to produce atleast a
                                                      item. Suppose ready was 1 and if
                                                      Consumer ran first he would be in an
                                                      empty buffer */
              critical=new Semaphore (1,false);/*We initialise it to 1 because when
                                                      the first Consumer thread tries
                                                      to enter its critical section, it
                                                      should be allowed to;
                                                      Subsequent threads will have to
                                                      wait since only 1 thread can
                                                      access its critical section at a time*/
              counter=new Semaphore(0,false); // duh!
              cons=new Consumer[numberOfThreads-1]; /*numberOfThreads-1 because 1 thread
                                                                is taken by the Producer*/
              //Creating Producer object
              prod=new Producer();
              //Creating the Consumer object and start the thread.
              for(int i=0;i<cons.length;i++)
                        cons[i]=new Consumer();
                        cons[i].start();
              prod.start();          
              //Printing to screen and file
    /*          for(int i=0;i<buffer.length;i++)
                   if(buffer[i]!=0)
                             System.out.println(buffer[i]);
                             outFile.println(buffer[i]);
              System.out.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits()+"\n primes.txt written");
              outFile.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits());
              outFile.close();*/                    
    static class Producer extends Thread {
         public void run(){try{
              while(in<buffer.length)     /*'in' should always be more than 'out'.Oherwise the consumer will try to access an empty index*/
                   {     System.out.println("producing");     
                        buffer[in]=fromThisNumber;
                        in++;
                        fromThisNumber++;
                        ready.release();
              catch (Exception e){e.printStackTrace();}
              System.out.println("ALL PRODUCING DONE");
    static class Consumer extends Thread {
         int tempout=0;
         public void run(){try{
              System.out.println("before while"+this.getId());
              while(tempout<=in)
                   System.out.println("before ready"+this.getId()+" "+ready.availablePermits()+" "+in);
                   ready.acquire();
                   System.out.println("before critical.acquire"+this.getId());
                   critical.acquire();
                   tempout=out;
                   out++;
                   critical.release();               
                   if(!isPrime(buffer[tempout]))
                        {System.out.println(buffer[tempout]+" by "+this.getId());buffer[tempout]=0;}
                   else {counter.release();System.out.println("prime added: "+buffer[tempout]+" by "+this.getId());}
                   critical.acquire();
                   tempout=out;
                   System.out.println("tempout:"+tempout+" of "+this.getId());
                   critical.release();
              System.out.println("ALL CONSUMING DONE"+this.getId());
         catch(Exception e){e.printStackTrace();}
         //Prime number-checking method     
         public boolean isPrime(int n){
              for(int i=2;i<=(n/2);i++)
                   if(n%i==0)
                        return false;
              return true;
    ===========================
    BTW, when I tried to change extends Thread to implements Runnable I got some kinda of error.
    Actually, my program is pretty complete... its just that something if messed up in my Consumer's run() method's while loop... I think
    I know guys its crazy to ask ya'll to look at so much code, but.... I'd really appreciate it. This assignment is killing me, been at it since 10 hours now....

  • How to get value from Thread Run Method

    I want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that it seems that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get Inside the run method::: But I get only Inside */
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";

    I think this is what you're looking for. I hold up main(), waiting for the results to be concatenated to the String.
    public class sampsynch
        class SampleThread extends Thread
         String x = "Inside";
         public void run() {
             x+="the run method";
             synchronized(this) {
              notify();
        public static void main(String[] args) throws InterruptedException {
         SampleThread t = new sampsynch().new SampleThread();
         t.start();
         synchronized(t) {
             t.wait();
         System.out.println(t.x);
    }

  • Unsatisfied link when callind dll from run method Help Please?

    Hi,
    I get an unsatisfied link error while trying to calling a dll at a certain time period in a run method. The same dll works fine called in another setup and even called in a loop.
    Can anyone help please?
    import java.util.Timer;
    import java.util.TimerTask;
    * Schedule a task that executes once every second.
    public class TimeRetrieve {
        Timer timer;
        public TimeRetrieve() {
                 timer = new Timer();
            timer.schedule(new RemindTask(),
                        0,        //initial delay
                        1*1000);  //subsequent rate
        class RemindTask extends TimerTask
           String string_A;
           double d1;
         double d2;
         double d3;
         double d4;
         double d5;
         double d6;
         double d7;
         double d8;
         int numIter = 3;
         int start = 1;
            public void run()
                  if (numIter > 0) {
                  cinterface(start, string_A, d1, d2, d3, d4, d5, d6, d7, d8 );
              System.out.println("In Java action performed start button, after call to dll  \n");
              System.out.println("   string_A =  :" +string_A );
              System.out.println("doubles , \t  d1  \t d2  \t  d3  \t d4 \t d5 \t d6 \t d7 \t d8");
              System.out.println(d1 +"\t" +d2+"\t"+d3+"\t"+d4+"\t"+d5+"\t"+d6+"\t"+d7+"\t"+d8);
              numIter--;
                 } else
                 System.out.println("End Looping!");
                    System.exit
                 System.exit(0);  
        public static void main(String args[]) {
                   System.out.println("Starting Data Retrieval.");
                 new TimeRetrieve();
    // Load shared library which contains implementation of native methods
                    public native void cinterface(int start, String string_A, double d1, double d2, double d3, double d4,
                    double d5, double d6, double d7, double d8 );
                    static
                          try
                               System.out.println ("load cinterface"); //unsatisfied link
                               System.loadLibrary("cinterface");
                          catch (UnsatisfiedLinkError ee)
                               System.out.println
                                    ("Caught unsatisfied link error for dlls" );
                               System.out.println
                                    ("get local msg = " + ee.getLocalizedMessage() );
                               System.out.println ("getMessage " + ee.getMessage() );
                                   // System.out.println ("print Stack Trace " +ee.printStackTrace() );

    My mistake! I found it. Had some wrong names.

  • How to throw exception in run() method of Runnable?

    Hi, everyone:
    I want to know how to throw exception in run() method of interface Runnable. Since there is no throwable exception declared in run() method of interface Runnable in Java API specification.
    Thanks in advance,
    George

    Thanks, jfbriere.
    I must add though that if your run() methodis
    executed after a call to Thread.start(), then
    it is not a good choice to throw anyRuntimeException
    from the run() method.
    The reason is that the thrown exception won't be
    handled appropriately by a try-catch block.Why do you say that "the thrown exception won't be
    handled appropriately by a try-catch block"? Can you
    explain it in more detail?
    regards,
    George
    Because the other thread runs concurrently with and independently of the parent thread, there's no way you can write a try/catch that will handle the new thread's exception: try {
        myThread.start();
    catch (TheExceptionYouWantToThrowFromRun exc) {
        handle it
    do the next thing This won't work because the parent thread just continues on after myThread.start(). Start() doesn't throw the exception--run() does. And our parent thread here has lost touch with the child thread--it just moves on to "do the next thing."
    Now, you can do some exception handling with ThreadGroup and uncaughtException(), but make sure you understand why the above won't work, in case that was what you were planning to do.

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • How to throw Exception in Thread.run() method

    I want to throw exception in Thread.run() method. How can I do that ?
    If I try to compile the Code given below, it does not allow me to compile :
    public class ThreadTest {
         public static void main(String[] args) {
         ThreadTest.DyingThread t = new DyingThread();
         t.start();
         static class DyingThread extends Thread {
         public void run() {
         try {
                   //some code that may throw some exception here
              } catch (Exception e) {
              throw e;//Want to throw(pass) exception to caller
    }

    (a) in JDK 1.4+, wrap your exception in RuntimeException:
    catch (Exception e)
    throw new RuntimeException(e);
    [this exception will be caught by ThreadGroup.uncaughtException() of this thread's parent thread group]
    In earlier JDKs, use your own wrapping unchecked exception class.
    (b) if you know what you are doing, you can make any Java method throw any exception using Thread.stop(Throwable) regardless of what it declares in its "throws" declaration.

  • Passing parameters to run() method of a thread?

    hello ppl
    is it possible to pass any parameters to the run() method of a thread
    moreover if i create a thread foo the only method that can run is run() ? i know that i can have more methods and just call them via run().
    i mean that if i create the constructor of the foo class then first the constructor will be called and then the run() method.but in this way only the code inside run() will run autonomously(meaning that for example i'll be able to press a button of my gui).
    thx in advance. =)

    not sure I understand the question completely, but you can try the following. Set up whatever arameters your requiring as member variables of your Runnable. Overload the run() method with parameter list you need. In this overloaded method initialize the member variables in your runnable, which can be used in the run() , no arg version,/ Then the last line of the overloaded version call run(), again no-arg version.
    Not really familiar with thread programming, but I dont see why this wont work.
    Hopefully I understood the question correctly, and this is of some help...

  • When we create JDialog inside Thread's run() method it is creating problem

    I have application that has feature that mainframe will be locked after three minutes and the time when it is locked it will show other locked dialog.
    Now my problem is given below:
    I have created one Dialog inside Threads run() method and this thread will execute when mainframe is locked.So what is happening is when mainframe is locked internally Thread is doing its job (its job is to display one dialog) and it is displaying dialog but mainframe is locked and still it is showing that dialog.This should not happen in our application when mainframe is locked nothing should come outside.
    simple code sample is given below:
    SwingUtilities.invokeLater(new Runnable()
    JDailog dlg = new JDialog();
    dlg.pack();
    dlg.show();
    Now when my applications mainframe is locked and thread is doing its job when mainframe is locked and it will show one dialog when its run() method will execute and it showing dialog even though mainframe is locked.This is major issue for me.please help me.
    sample code may contain compile errror but this only to give understanding what i am doing actually i cant show my original code.
    But show me some work around for this problem.Why dialog is coming outside when mainframe is locked?
    Please help me.I cant use delay inside run() method because of performance.
    Is there any way to control this behaviour?

    public class BackGroundThread extends javax.swing.JFrame implements BackgroundTaskInf {
        boolean isMainWindowActive = false;
        /** Creates new form BackGroundThread */
        public BackGroundThread() {
            initComponents();
            new DBBackgroudProcess(this).start();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jDialog1 = new javax.swing.JDialog();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jLabel1.setText("JOB DONE");
            javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
            jDialog1.getContentPane().setLayout(jDialog1Layout);
            jDialog1Layout.setHorizontalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addGap(95, 95, 95)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(240, Short.MAX_VALUE))
            jDialog1Layout.setVerticalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(jLabel1)
                    .addContainerGap(22, Short.MAX_VALUE))
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jLabel2.setText("Background work in progess");
            jButton1.setText("unlock");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(56, 56, 56)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(126, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(263, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(74, 74, 74))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(40, 40, 40)
                    .addComponent(jLabel2)
                    .addGap(37, 37, 37)
                    .addComponent(jButton1)
                    .addContainerGap(43, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            isMainWindowActive = true;
            backgroundTaskFinished();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new BackGroundThread().setVisible(true);
        public void backgroundTaskFinished(){
            if(isMainWindowActive) {
                jDialog1.setSize(200,200);
                jDialog1.setVisible(true);
                jLabel2.setText("Task is finished");
        // Variables declaration - do not modify                    
        private javax.swing.JButton jButton1;
        private javax.swing.JDialog jDialog1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        // End of variables declaration                  
    class DBBackgroudProcess extends Thread {
        BackgroundTaskInf infObj;
        public DBBackgroudProcess(BackgroundTaskInf infObj){
            this.infObj = infObj;
        public void run(){
            try{
                // here you can do your backgroudn task
                System.out.println("In BackGroud task");
                Thread.sleep(1000);
                System.out.println("task completed");
                infObj.backgroundTaskFinished();
            }catch(Exception e){
                e.printStackTrace();
    interface BackgroundTaskInf{
        public void backgroundTaskFinished();
    }

  • Stopping a Thread (no control on run method)

    Hi,
    How can we stop a Thread like in the following scenario. If we are in the aMethod() and the stopped variable is set to true by some other thread now how can we return from this run method and stop executing the aMethod(). Any tips are helpful.
    public void run()
    if (stopped)
    return;
    someOtherClass.aMethod();
    Thanks

    I miss the scenario here, where a thread is blocked inside a call to some operating system resource (such as accept() or read() or write()).
    In this case an InterruptedException travels like pacman up the stack, until it's caught, and I think that it should be a scenario in all cases, because it can apply to the blocking call (where it applies already), the predictable loop (try { while() { } } catch (InterruptedException ie) { }), and the one-off algorithm, even though in the latter case, if it's extremely important that we know exactly what we were doing when we were interrupted, it's difficult to avoid either a) many try-catch-blocks, or b) a very good way of examining the stack at the moment of interruption.
    This is, in fact, so important, that I would like to urge Sun to change the API for java.lang.Runnable into
    public interface Runnable {
      public abstract void run() throws InterruptedException;
    }Because, in this way, any thread will always have an endpoint. If you choose to rethrow the exception you still mess up the JVM, of course, like it was, causing it to exit. But at least you must provide yourself with the opportunity to let threads not end, or always die softly.

  • Resource registration is failing - Couldnt run method tag. Error in execve

    Hi,
    We have solaris cluster setup with two nodes and a resource group exists which contains a zfs resource which could be mounted on to one of the nodes in the cluster.
    Our application is installed on one of the directory in the zfs file system. The file system and the application would be to be on one of the nodes and if somethings goes bad, it shoud failover to other node.
    I used Agent Builder to create new resource type for managing our application part of sun cluster and used the ksh mode providing it start/stop/probe scripts. I have left validate script as blank.
    When I try to register this new resource type, (resource time generated folder/util/start* script,
    nodex /u2/appx/cluster/ResourceType_01/XYZSolarisAPPXClusterL0/util % ls -ltr
    total 71
    -rw-r--r-- 1 appowner appowner 13960 Jan 12 07:36 startSolarisAPPXClusterL0 <---
    -rw-r--r-- 1 appowner appowner 8281 Jan 12 07:36 removeSolarisAPPXClusterL0
    -rw-r--r-- 1 appowner appowner 7316 Jan 12 07:36 stopSolarisAPPXClusterL0
    -rw-r--r-- 1 appowner appowner 2300 Jan 12 07:36 SolarisAPPXClusterL0_config
    # Resource group creation was successful (SolarisAPPXClusterL0-harg)
    # Virtual Host resource creation was successfull
    # It got added to the new group created
    # But it is failing when it is attempting to create resource for the new resource type - SolarisAPPXClusterL0-hars
    Error:
    Jan 17 14:52:01 nodex Cluster.RGM.global.rgmd: [ID 224900 daemon.notice] launching method <SolarisAPPXClusterL0_validate.ksh> for resource <SolarisAPPXClusterL0-hars>, resourcegroup <SolarisAPPXClusterL0-harg>, node <nodex>, timeout <300> seconds
    Jan 17 14:52:01 nodex Cluster.RGM.fed: [ID 838032 daemon.error] SolarisAPPXClusterL0-harg.SolarisAPPXClusterL0-hars.2: Couldn't run method tag. Error in execve: No such file ordirectory.
    Jan 17 14:52:01 nodex Cluster.RGM.global.rgmd: [ID 699104 daemon.error] VALIDATE failed on resource <SolarisAPPXClusterL0-hars>, resource group <SolarisAPPXClusterL0-harg>, time used: 0% of timeout <300, seconds>
    The new resource type files are available on nodex and nodey. When we try to remove and start it again, the error occurred on the other nodey with similar error.
    Jan 17 14:33:52 nodey Cluster.RGM.global.rgmd: [ID 224900 daemon.notice] launching method <hafoip_validate> for resource <failover-clus1>, resource group <SolarisAPPXClusterL0-harg>, node <nodey>, timeout <300> seconds
    Jan 17 14:33:52 nodey Cluster.RGM.global.rgmd: [ID 515159 daemon.notice] method <hafoip_validate> completed successfully for resource <failover-clus1>, resource group <SolarisAPPXClusterL0-harg>, node <nodey>, time used: 0% of timeout <300 seconds>
    Jan 17 14:33:53 nodey Cluster.RGM.global.rgmd: [ID 224900 daemon.notice] launching method <SolarisAPPXClusterL0_validate.ksh> for resource <SolarisAPPXClusterL0-hars>, resourcegroup <SolarisAPPXClusterL0-harg>, node <nodey>, timeout <300> seconds
    Jan 17 14:33:53 nodey Cluster.RGM.fed: [ID 838032 daemon.error] SolarisAPPXClusterL0-harg.SolarisAPPXClusterL0-hars.2: Couldn't run method tag. Error in execve: No such file ordirectory.
    Jan 17 14:33:53 nodey Cluster.RGM.global.rgmd: [ID 699104 daemon.error] VALIDATE failed on resource <SolarisAPPXClusterL0-hars>, resource group <SolarisAPPXClusterL0-harg>, time used: 0% of timeout <300, seconds>
    Are there other logs than /var/adm/messages to check for errors ?
    What is causing this error ? Any help is appreciated.
    Thanks in advance!

    See if adding the execute permissions to the scripts solve the problem.
    In general, I just use the SUNW.gds resource type directly rather than use the agent builder. If you want to build something a little more complex, then I would recommend sub-classing the SUNW.gds agent. There are a number of Oracle supplied agents that do this, for example, the HA-LDoms, and HA-obiee agents. Have a look at how they work.
    Regards,
    Tim
    ---

  • How to use run() method in serlvets

    Hi,
    I want to execute run() method in servlet as i have got a web application where in I want to set timer for the choosen times and want to pop up when ever the time elapses..can anybody help
    Thanks,
    veni..

    The API documentation has a link at the top of every page that says "Index". If you follow that and look for toFront(), you will find it exists in java.awt.Window and javax.swing.JInternalFrame.
    To use it in a Java application, create an object x of either of those two classes and write "x.toFront();".

  • Overload run method

    Hi all,
    is it possible to overload the run method of a Thread.
    Thank You
    Panikiran

    Based on your question, I have a sneaking suspicion that you believe an overloading method is somehow related to the overloaded method in a way other than just happening to have the same name.
    ~

  • Is it possible to throw an exception from run method of a thread?

    Is it possible to throw an exception from "run method of a thread"(implemented as runnable implementation)?
    Is it advisable to do so?

    Is it possible to throw an exception from "run method
    of a thread"(implemented as runnable
    implementation)?Yes, an unchecked one. Runtime exceptions.
    Is it advisable to do so?If you mess up it happens automatically. But basically: no.

Maybe you are looking for

  • How do I get smileys to appear in Pages?

    I followed the Help instructions for Special Characters - NO JOY.  I double click on face and it puts a blank space. I added face to Auto-Correction Pref - NO JOY.  It leaves a blank space.

  • How to filter Billing Document Date

    Hello SAP Consultant I'm using vbrk and vbrp to fetch the data according to selection screen. Also i'm using Billing Document no as vbrp-vbeln and Billing date vbrp-fkdate. But i'm not able to filter the data according to billing document date. I'm u

  • Approver SAP ID for purchase requesition

    Dear team, I have approver workflow for Purchase Requesition, now I want to pull the history of PR from 2012 to 2015 current month. Here main requirement is the approver name who has approved the PR, but don't find any standard report or table where

  • Oracle JDBC Driver too old in Oracle WebLogic Server 10.3

    I check oracle jdbc driver bundles in the Oracle WebLogic Server 10.3 The version is too old,and current version is: Oracle Database 11g Release 1 (11.1.0.7.0) JDBC Drivers The question is: Could we replace the old ojdbc6.jar with the current one (11

  • Have old shuffle..can't find my itunes library!

    Have 2 issues. One, I have an old shuffle that I'd rather not change the content, just recharge it..and so it does..but..my music library never showed up and I am sure that I have downloaded itunes on this computer..and that my library showed up on i