Will more number of waiting threads in thread pool degrade performance?

Hi,
I use thread pool and set the maximum number of threads to execute. My problem is, the thread pool initiates the number of threads and these threads wait until they get a work. Will this degrade the performance (The threads do I/O operations) ??

Threads waiting for work will not degrade performance. If your work involves those threads waiting for I/O then that in itself will not degrade performance either (as long as they block and don't poll of course).
All live threads consume resources however so if you are short on threads or memory then don't create too many of them.
Pre-starting a large number of threads in a pool can cause a startup delay of course. Generally you should let the pool create threads as needed until it gets to the core pool size.

Similar Messages

  • Java.lang.IllegalStateException: Exceeded maximum number of waiting threads

    Hi all,
    I use coherence3.3.1,coherence work as hibernate L2 cache and meet following problem,could you help me check the problem?thanks.
    java.lang.IllegalStateException: Exceeded maximum number of waiting threads (Status=2)
         at com.tangosol.net.cache.OverflowMap$Status.waitForAvailable(OverflowMap.java:4029)
         at com.tangosol.net.cache.OverflowMap.prepareStatus(OverflowMap.java:2152)
         at com.tangosol.net.cache.OverflowMap.beginKeyProcess(OverflowMap.java:1873)
         at com.tangosol.net.cache.OverflowMap.getInternal(OverflowMap.java:580)
         at com.tangosol.net.cache.OverflowMap.get(OverflowMap.java:330)
         at com.tangosol.coherence.component.util.CacheHandler.getLease(CacheHandler.CDB:3)
         at com.tangosol.coherence.component.util.CacheHandler.getCachedResource(CacheHandler.CDB:10)
         at com.tangosol.coherence.component.util.CacheHandler.get(CacheHandler.CDB:1)
         at com.tangosol.coherence.component.util.SafeNamedCache.get(SafeNamedCache.CDB:1)
         at com.tangosol.coherence.hibernate.CoherenceCache.get(CoherenceCache.java:65)
         at org.hibernate.cache.StandardQueryCache.get(StandardQueryCache.java:105)
         at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2152)
         at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2117)
         at org.hibernate.loader.Loader.list(Loader.java:2087)
         at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
         at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
         at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
         at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
         at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:804)
    j

    Hi,
    Can you please provide the relevant coherence config files?
    thanks,
    -Rob

  • Submit submit a large number of task to a thread pool (more than 10,000)

    i want to submit a large number of task to a thread pool (more than 10,000).
    Since a thread pool take runnable as input i have to create as many objects of Runnable as the number of task, but since the number of task is very large it causes the memory overflow and my application crashes.
    Can you suggest me some way to overcome this problem?

    Ravi_Gupta wrote:
    I have to serve them infinitely depending upon the choice of the user.
    Take a look at my code (code of MyCustomRunnable is already posted)
    public void start(Vector<String> addresses)
    searching = true;What is this for? Is it a kind of comment?
    >
    Vector<MyCustomRunnable> runnables = new Vector<MyCustomRunnable>(1,1);
    for (String address : addresses)
    try
    runnables.addElement(new MyCustomRunnable(address));
    catch (IOException ex)
    ex.printStackTrace();
    }Why does MyCustomRunnable throw an IOException? Why is using up resources when it hasn't started. Why build this vector at all?
    >
    //ThreadPoolExecutor pool = new ThreadPoolExecutor(100,100,50000L,TimeUnit.MILLISECONDS,new LinkedBlockingQueue());
    ExecutorService pool = Executors.newFixedThreadPool(100);You have 100 CPUs wow! I can only assume your operations are blocking on a Socket connection most of the time.
    >
    boolean interrupted = false;
    Vector<Future<String>> futures = new Vector<Future<String>>(1,1);You don't save much by reusing your vector here.
    for(int i=1; !interrupted; i++)You are looping here until the thread is interrupted, why are you doing this? Are you trying to generate loading on a remote server?
    System.out.println("Cycle: " + i);
    for(MyCustomRunnable runnable : runnables)Change the name of you Runnable as it clearly does much more than that. Typically a Runnable is executed once and does not create resources in its constructor nor have a cleanup method.
    futures.addElement((Future<String>) pool.submit(runnable));Again, it unclear why you would use a vector rather than a list here.
    >
    for(Future<String> future : futures)
    try
    future.get();
    catch (InterruptedException ex)
    interrupted = true;If you want this to break the loop put the try/catch outside the loop.
    ex.printStackTrace();
    catch (ExecutionException ex)
    ex.printStackTrace();If you are generating a load test you may want to record this kind of failure. e.g. count them.
    futures.clear();
    try
    Thread.sleep(60000);Why do you sleep even if you have been interrupted? For better timing, you should sleep, before check if you futures have finished.
    catch(InterruptedException e)
    searching = false;again does nothing.
    System.out.println("Thread pool terminated..................");
    //return;remove this comment. its dangerous.
    break;why do you have two way of breaking the loop. why not interrupted = true here.
    searching = false;
    System.out.println("Shut downing pool");
    pool.shutdownNow();
    try
    for(MyCustomRunnable runnable : runnables)
    runnable.close(); //release resources associated with it.
    catch(IOException e)put the try/catch inside the loop. You may want to ignore the exception but if one fails, the rest of the resources won't get cleaned up.
    The above code serve the task infinitely untill it is terminated by user.
    i had created a large number of runnables and future objects and they remain in memory until
    user terminates the operation might be the cause of the memory overflow.It could be the size of the resources each runnable holds. Have you tried increasing your maximum memory? e.g. -Xmx512m

  • Waiting the main thread till all child thread has completed

    I am in the process of developing a batch application in Java 5.0 which extensively uses the java.util.concurrency API. Here is a small description of what the batch process will do,
    1. Retrieve values from DB and populate a blocking queue in main thread.
    2. Instantiate a Threadpool by calling, Executors.newFixedThreadPool(2)
    3. Invoking the following block of code from the main thread,
    while(!iBlockingQueue.isEmpty()) {
        AbstractProcessor lProcessor = new  DefaultProcessor((BusinessObject)iBlockingQueue.remove());
        iThreadPool.execute(lProcessor);
    }DefaultProcessor is a class that extends Thread.
    4. Invoking the following block of code from the main thread,
    iThreadPool.shutdown();
    try {
         iThreadPool.awaitTermination(30, TimeUnit.SECONDS);
         } catch (InterruptedException interruptedException) {
              iLogger.debug("Error in await termination...", interruptedException);
    Since, this is the first time I am using the java.util.concurrency API, I want to know whether this is the right way to wait for all the child threads to complete before executing further statements in the main (parent) thread. Or do I necessariliy have to call join() to ensure that the main thread waits for all the child threads to finish which can only happen when the queue is empty.
    Please note here that as per the requirements of the application the blocking queue is filled only once at the very beginning.
    I will appreciate any inputs on this.
    Thanks.

    looks like you would be waiting on a queue twice, once in the loop and again, under the hood, in the threadpool's execute()
    the threadpool's internal queue is all that is needed
    if your iBlockingQueue is also the threadpool's internal queue, you might have a problem when you remove() the BusinessObject
    by making DefaultProcessor extend Thread you are, in effect, implementing your own threadpool without the pooling
    DefaultProcessor need only implement Runnable, it will be wrapped in a thread within the pool and start() called
    to implement a clean shutdown, I suggest writing DefaultProcessor.run() as an infinite loop around the blocking queue poll(timeout) and a stop flag that is checked before going back to poll
    class DefaultProcessor implements Runnable {
      private BlockingQueue myQ;
      private boolean myStopFlag;
      DefaultProcessor( BlockingQueue bq ) { myQ = bq; }
      public void run() {
        BusinessObject bo = null;
        while( !myStopFlag && (bo=myQ.poll( 10, SECONDS )) ) {
          // business code here
      public void stop() { myStopFlag = true; }
    } Now, after iThreadPool.shutdown(), either call stop() on all DefaultProcessors (or alternatively send "poison" messages to the queue), and give yourself enough time to allow processing to finish.

  • Waiting for a thread to die.

    Hello, I hope you can help me...
    I am writting a jdk1.4.1 Swing application that displays a small animation. This animation is processed from within a separate thread. My program makes a call starting this 'animation thread'. For practical reasons my program needs to wait for this thread to die (and thus the full animation to be shown) before it can continue. I am waiting for the animation thread to die using Threads 'join' method. However the problem with this is that I am forcing the GUI thread to wait resulting in the animation being calculated but not displayed. And so... how can I fix this... all I want is to wait until the animation is shown.
    What I would like to do is:
    1. Start animation;
    2. wait intil animation has completed;
    3. continue with program.
    Any help or advice will be greatly appreciated.
    Thank you in advance.

    Maybe this design could work for you. You divide your program into three parts running in three separate threads.
    1. The main thread handling GUI stuff and coordination of the two other threads.
    2. A working thread doing most of what the main thread is now doing.
    3. The animation thread.
    With this division of labour the working thread is waiting for the animation thread to finish (the main GUI thread isn't). The main thread will be free at all times to react to the users input or updating the screen or whatever, while the other two threads are cooperating to produce the animation.

  • Unable to view number of messages in a thread

    Frustrated user here who opens Mail to find that the View bar (don't know what to call it - it is that blue dot) no longer shows the number of messages in a thread. This would be bad enough - but Mail will NOT let me expand the (Read Status?) (Thread Status?) to show the number of unread threads. I can hover the mouse over the divider bar in the "To" field to make it larger or smaller. I can hover the mouse over the divider in the "Subject" field to make it larger or smaller. Same with most (but not all) of the fields. Normally, I can expand the "blue dot" (what the heck is it called????) field, but today I can't. Last time I had this problem - maybe a year ago - I could do nothing to solve it, until about a month later when in just started working again. Help anyone? OS X 10.5.2 on an iMac (20-inch Mid 2007).

    The problem mysteriously went away - just like it did the last time it happened. I can now expand the field to reveal how many messages there are in the threads. I suspect a problem with .mac mail. Maybe there are times when it doesn't know the message count (hard to say why). Anyway - the problem is not solved, but it is not (currently) present.

  • Hi Guys! Will you share your thoughts on a Thread issue?

    Hi! I am working on figuring out how to get my application to use threads to enable the simultaneous movement of (n) balls across the JFrame area. The task is to enable the user to click on the application and with each click a new ball should be created as a Thread and then it should bounce back and forth across the screen.
    I have been working on this now for a couple of days. It would be really great if one of you guys could help me! :-)
    Here are my specific issues:
    I am using the mousePressed() method to generate the data needed to instantiate a Ball object. However, I cannot get it to work as a Thread.
    I tried calling the start() method on it but all that happens is the application stays blank.
    I cannot get this thing to work -and I really need to make it work today -- Please --- is there a sweetheart out there who will take a minute to help? ;-)
    Jennifer
    My code is below:
    Balls.java
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Balls extends JFrame implements MouseListener
          private int x, y, r, g, b;//Variables to hold x,y and color values
          private Vector basketOBalls;//Hold all of the Ball objects (and Threads created)
          private Ball ballFactory;//Ball objects created here
            Method Name: Balls()
            Return Value: none
            Input Parameters: None
            Method Description: Constructor
          public Balls()
            //call to super for Title of app
            super( " Bouncing Balls " );
            //Listen for mouse events
            addMouseListener( this ); 
            //instantiate the basketOBalls object
            basketOBalls = new Vector(20);
                //Set Initial JFrame Window Size
            setSize( 400, 400 );
         //Show it!
         show();
         }//EOConstructor
            Method Name: mousePressed(MouseEvent e)
            Return Value: none
            Input Parameters: MouseEvent
            Method Description: This takes the info from the users
            mouse click and creates a new Ball Object and then adds it
            to the basketOBalls Vector. Presently, it (incorrectly?) also
            calls the repaint() method in order to draw the ball to the
            screen.
           public void mousePressed( MouseEvent e )
               x = e.getX();//set x value
               y = e.getY();//set y value
               r = 1 + (int) ( 254 * Math.random() );//set red value
               g = 1 + (int) ( 254 * Math.random() );//set green value
               b = 1 + (int) ( 254 * Math.random() );//set blue value
               Color colorin = new Color( r, g, b );
               ballFactory = new Ball( x, y, colorin );
               //new Thread(ballFactory).start(); //This is the Problem area!!!!!!!!!!!!!!!!!!!!!
               basketOBalls.addElement( ballFactory );
               repaint();
            }//EOmP
            Method Name: paint( Graphics g )
            Return Value: none
            Input Parameters: Graphics Object g
            Method Description: Walk through the Vector to
            explicitly cast each object back as a Ball and
            then calls the Ball draw() and ball move() methods
            in order to make the balls move on the screen.
        public void paint( Graphics g )
            Ball b;
            for( int i = 0; i < basketOBalls.size(); i++)
               b = (Ball) (basketOBalls.elementAt(i));
               b.draw(g);
               b.move();
            }//EOFor
          }//EOpaint
            Method Name: main()
            Return Value: none
            Input Parameters: String args[]
            Method Description: This makes it all go.
          public static void main( String args[] )
            Balls app = new Balls();
            app.addWindowListener(
              new WindowAdapter()
                     public void windowClosing( WindowEvent e )
                                    System.exit(0);
                     }//EOwindowClosing Method
              }//EOWindowAdapter Method
              );//EOaddWindowListener Argument
          }//EOMain
        public void mouseClicked( MouseEvent e ) { }
        public void mouseReleased( MouseEvent e ) { }
        public void mouseEntered( MouseEvent e ) { }
        public void mouseExited( MouseEvent e ) { }
    }//EOFBall.java
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Ball extends JFrame //implements Runnable
            public static final int APP_SIZE = 400;//set bounds for screen area
         public static final int RADIUS = 15;//set size of balls
            private Color bgColor = java.awt.Color.lightGray;//may be used to clear background of JFrame
         private int x, y;//x & y coordinates
         private int speedX, speedY;//distances to use to redraw the balls
            private Color color = null;//the color of a ball
            Method Name: Ball(int initX, int initY, Color colorin) 
            Return Value: none
            Input Parameters: int, int , color
            Method Description: Constructor that creates a Ball object
         public Ball(int initX, int initY, Color colorin)
              x = initX;
              y = initY;
                    color = colorin;
                 speedX = (int)(1 + (Math.random() * 10));
              speedY = (int)(1 + (Math.random() * 10));
            Method Name: move()
            Return Value: none
            Input Parameters: none
            Method Description: This calculates the balls position and keeps it within
            the 400 pixel size of the application frame.
         public void move()
              x += speedX;
              y += speedY;
              if ((x - RADIUS < 0) || (x + RADIUS > APP_SIZE))
                   speedX = -speedX;
                   x += speedX;
              if ((y - RADIUS < 0) || (y + RADIUS > APP_SIZE))
                   speedY = -speedY;
                   y += speedY;
         } //EOMove
            Method Name: draw(Graphics bg) 
            Return Value: none
            Input Parameters: graphics
            Method Description: This method is how the ball draws itself
            public void draw(Graphics bg)
                bg.setColor( color );
                bg.fillOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
    //PROBLEM AREA PROBLEM AREA PROBLEM AREA PROBLEM AREA PROBLEM AREA PROBLEM AREA
            Method Name: run() 
            Return Value: none
            Input Parameters: none
            Method Description: This method is called by start() in the Balls.java file
            found in the mousePressed() method. however, it does not work properly.
         public void run()
               while(true)
              try
                 Thread.sleep(100);
                       move();
                       draw(g);
                       repaint();
                    catch(Exception e)
                    e.printStackTrace( System.out );
        }//EOF

    There needs to be only one thread. On every mouse pressed just add a new Ball object to the vector located in Balls class. That thread need only invoke a repaint on your main class called Balls.
    public class Balls extends JFrame implements Runnable,MouseListener{
    Vector vector = new Vector();
    public static void main(String[] args){
    Balls balls = new Balls(); balls.setSize(400,400);
    balls.setVisible(true);
    Thread thread = new Thread(this);
    thread.start();
    public void run(){ 
    while(true){
    repaint();
    try{
    Thread.sleep(4000); //delay
    }catch(InterruptedException e){}
    public void paint(Graphics){
    for(i=0; i<vector.size(); i++){
    Ball b = (Ball)vector.elementAt(i);
    reposition(b);
    g.drawArc(b.getX(),b.getY(),0,360);
    public void reposition(Ball b){
    // reposition ball using balls get/set methods.
    public void MouseClicked(MouseEvent e){
    // add a new ball to vector.
    public class Ball{
    int x,y;
    public int getX(){ return x; }
    public int getY(){ return y; }
    public int setX(int x){ this.x = x; }
    public int setY(int y){ this.y = y; }
    Do check the syntax and compilation errors. The code above should give you some idea for approach.

  • How to count number of viewer of a thread in sharepoint discussion board.

    HI All,
    I am working on sharepoint discussion board, I want to calculate the total number of viewers of a thread.
    Just like a thread in MSDN forum Replies & Views.
    is there any column in sharepoint discussion board to get number of views.
    please tell me the approach or share the C# code.
    thanks

    hello
    you can use Sharepoint Audit feature - see
    SPAudit class for details. Also check this link:
    Number of times a post has been viewed in SharePoint Discussion Board
    Blog - http://sadomovalex.blogspot.com
    CAML via C# - http://camlex.codeplex.com
    Graphs visualization in Sharepoint - http://spgraphviz.codeplex.com

  • Wait for all threads in a array to die

    I everyone. I'm from Portugal and I have some experience in JAVA programming (approximately five years) but this is the first the first time that i'm trying to use threads. I'm trying to learn writing some simpler code that does almost exactly at the basic level the same stuff that a complex application that I need to write for my work.
    What I'm trying to do is execute a counter that counts all operations in threads belonging to the same array (an array of n threads).
    A static variable in the Thread class (implementing Runnable) counts all operations performed by all threads and sums them all and shoud display the total of operations after all threads terminate, but this exactly what I don't know how to do:
    This is my example code:
    public class TT1 implements Runnable {
         int id;
         double last_number;
         static int threads_counter = 0;
         static int total_threads = 4;
         static long total_numbers;
         int total_randoms = 1000;
         public void run() {
              for (int i=0;i<total_randoms;i++)
                   total_numbers++;
                   // does some stuff, in this case, generate a random number!
                   last_number = Math.random();
              System.out.printf("Thread %d:%f(%d)\n",id,last_number,total_numbers);
         public TT1() {
              id = threads_counter++;
              new Thread(this).start();
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Thread [] threads = new Thread[total_threads];
              for (int i=0;i<threads.length;i++)
                   threads[i] = new Thread(new TT1());
              /* commented code using join(), is not working or I don't know
              how to use it! */
              for (int i=0;i<threads.length;i++)
                   try {
                        threads.join();
                   } catch (InterruptedException e) {
                        e.printStackTrace();
              try {
                   threads[total_threads-1].join();
              } catch (InterruptedException e) {
                   e.printStackTrace();
              // this line should be executed ONLY after ALL threads have died!
              System.out.println("******GENERATED NUMBERS TOTAL:" + total_numbers);
    Somebody can give me a hint how to solve this ?

    Thanks for your replies.
    Actually, i've corrected the code, now i'm starting the threads outside the constructor. Originally I thought this could be a simpler way to create the threads: launching them at same time I'm creating them! Is this wrong ? :) Well, watching the results.
    I changed my code:
    public class TT1 implements Runnable {
         int id;
         double last_number;
         static int threads_counter = 0;
         static int total_threads = 4;
         static long total_numbers;
         int total_randoms = 1000;
         public void run() {
              for (int i=0;i<total_randoms;i++)
                   total_numbers++;
                   // does some stuff, in this case, generate a random number!
                   last_number = Math.random();
              System.out.printf("Thread %d:%f(%d)\n",id,last_number,total_numbers);
         public TT1() {
              id = threads_counter++;
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Thread [] threads = new Thread[total_threads];
              /* create individual threads */
              for (int i=0;i<threads.length;i++)
                   threads[i] = new Thread(new TT1());
              /* launch the threads (NEW CODE) */
              for (int i=0;i<threads.length;i++)
                   threads.start();
              /* commented code using join(), is not working or I don't know
              how to use it! */
              for (int i=0;i<threads.length;i++)
                   try {
                        threads[i].join();
                   } catch (InterruptedException e) {
                        e.printStackTrace();
              // this line should be executed ONLY after ALL threads have died!
              System.out.println("******GENERATED NUMBERS TOTAL:" + total_numbers);
    And I obtain the output:
    $ java TT1
    Thread 0:0,191546(1000)
    Thread 1:0,937476(2000)
    Thread 2:0,825079(3000)
    Thread 3:0,451367(4000)
    ******GENERATED NUMBERS TOTAL:4000Exactly as I want it!
    All is good when it works good ;)
    Best regards

  • Create standby maximum number of logfiles for each thread

    The oracle doc states this equation for appropriate number of standby redo log file groups
    (maximum number of logfiles for each thread +1) * maximum number of threads
    How do you get the maximum number of logfiles for each thread and the max thread?
    Thanks!

    If you are running RAC you can, in theory, be running with a diferent count
    of Online Redo Logs in each thread (instance).
    However, normally, you would have the same number of Redo Logs in each
    thread.
    The theoretical max is prescribed at the CREATE DATABASE and can be
    changed with a CREATE CONTROLFILE. If you do an
    ALTER DATABASE BACKUP CONTROLFILE TO TRACE
    the sql script in the tracefile shows the maximum number of logs and members.

  • Application waits for the thread to finish

    Hi all,
    I have a class let say test that extends Thread.
    In my application i say:
    test Xtest = new test();
    Xtest.start();
    System.out.println("Thread finished");
    I need my application to wait for the thread to finish for it to continue, i.e. in my example print "Thread finished" .
    Can someone help me.
    Thanks in advance for your help.
    Best regards,
    Saadi MONLA

    This should work:
    test Xtest = new test();
    Xtest.start();
    Xtest.join();
    System.out.println("Thread finished");

  • Maximum number of logfiles for each thread

    Hi all,
    When I configure a Standby Redo Log, to determine the appropriate number of standby redo log file groups, I should use the following formula:
    appropriate number of standby redo log file groups: (maximum number of logfiles for each thread + 1) * maximum number of threads
    My question is: how can I determine the maximum number of logfiles for each thread ? Is it the online redo log file per group? or total of redo log files in all groups?
    SQL> ed
    Wrote file afiedt.buf
      1* select group#, thread#, sequence#, members from v$log
    SQL> /
        GROUP#    THREAD#  SEQUENCE#    MEMBERS
             1          1         40          1
             2          1         38          1
             3          1         39          1

    user8994263 wrote:
    Hi,
    If you have 5 redo log groups on primary, do you suggest to create 6 standby redo log groups on standby?
    If yes, why ?
    -KalidasYou did two mistakes
    1) Responded to old question Posted: Jun 1, 2010 8:52 PM
    2) Its not your question & asking into others threads.
    -- Please lock this thread

  • Waiting for many threads

    Hey guys,
    I know how to make one thread wait for another named thread to complete, but how do u make a thread wait for many threads to complete with the added problem of not knowing the names of the threads your waiting for? Looked and been trying for ages but can't get anything to work.
    Thanx
    Lisa

    No i saw it, pehaps i should rephrase with a question, how would you go about giving all these threads a reference? If it ain't obvious already am not great with java and if someone could tell me how to give the threads spawned references it would be great.
    As ive explained the code is really long so am not going to waist peoples time by posting it. Here is basically how i am spawning the threads "willy-nilly" style.
         while ((p < searchTerms.size())&&(p < 30)){
             term = (searchTerms.elementAt(p)).toString();
             NetChecker nc = new NetChecker(term,excludedAdds,refWeb);
             searchClasses.addElement(nc);     
             new Thread(nc).start();
             p++;
         } the classes all return web addresses in a vector, thats why i need all the threads to complete so i can collect all the results
    Thanx
    Lisa

  • Wait screen and Thread

    Hi
    I am trying to build a general wait screen like this
    public class Wait extends javax.swing.JFrame {
        private Thread counterThread;
        private String titleWindow;
        public Wait(String title, Thread tr) {
            initComponents();
            this.setTitle(title);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
            counterThread = tr;
            try {
                URL url = new URL("file:///c:/Foronomos/resources/25-0.gif");
                Icon icon = new ImageIcon(url);
                jLabel1.setIcon(icon);
                jLabel1.setText("");
            } catch (Exception ex) {
          counterThread.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.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jButtonCancel = new javax.swing.JButton();
            jButtonStart = new javax.swing.JButton();
        }// </editor-fold>                       
    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {                                             
        counterThread.interrupt();
        // Variables declaration                     
        private javax.swing.JButton jButtonCancel;
        private javax.swing.JButton jButtonStart;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        // End of variables declaration                  
    }then am display the wait screen from a class creating a new thread
    ShowDocument showDocument = new ShowDocument();
    showDocument.showDocument(id, Main.searchDocuments.getQueryString());
    Thread counterThread = new Thread(showDocument, "showDocument");
    new Wait("Wait...",counterThread);
    ....my problem is that the wait screen delays to displayed on the screen an seems like to wait until the thread is finished
    Am i something missing here?

    TeoDim wrote:
    thanx for reply
    After the code new Wait("Wait...",counterThread);)
    i am not doing nothing.So you are doing something?
    Just if i press a button i want to display a screen with results from a long delay time query. So i want to display at that time a form with a messageFrom where are you execution the long running task? Where is it executing? Are you sure that you aren't using the AWT/Swing thread?

  • Object.wait(): IllegalMonitorStateException: current thread not owner

    How can I identify the owner? I searched the Thread*-Classes but didn't see any method which identifies the owner.

    Or, from the documentation for Object.wait():
         * The current thread must own this object's monitor.and
         * This method should only be called by a thread that is the owner
         * of this object's monitor. See the <code>notify</code> method for a
         * description of the ways in which a thread can become the owner of
         * a monitor. and
         * @exception  IllegalMonitorStateException  if the current thread is not
         *               the owner of the object's monitor.Seems like a lot of people are getting broken downloads nowadays that don't include the documentation :-(

Maybe you are looking for