Thread problem in swings

I have made an application in swings i have stored the class files in a system and call that class files by a batfile shortcut in two diff. pcs .and i am tring to get an value of a Jtextarea in an event When I tried to run this application at the same time from 2 diff PCS,with diff string input in text area It is giving me the same vlaue.
Tell me Y it is so.and how can i rectify it
javauser

Very strange... what makes you think that this is a threading problem?

Similar Messages

  • Thread problem in swing application?

    Hi,
    I have a doubt in GridLayout and Threads. I�m doing one small application which is accepting images and Alphabets. Actually, What I�m doing running images and alphabets(combinedly) in frequent intervals. For this I used GridLayout and Thread concept. But I have a problem in paint method. How to call the GridLayout frequently. In GridLayout , I�m putting Images and alphabets. Acutually in paint method , there are only drawString or drawImage or other methods. Is it possible to call my layout. Is so, can anybody help me in this regard. Is there any way to do it . please suggest me.
    Thanks,
    -Balaji
    My code follows:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.applet.Applet;
    import java.util.*;
    import java.io.*;
    public class GridLayEx2 extends Applet implements Runnable {
    private Random r = new Random();
    private Thread imageThread = null;
    GridLayout glt;
    public void init() {
    glt = new GridLayout(3,3);
    setLayout(glt);
    } // end of init method
    public void start(){
    if (imageThread == null) {
    imageThread = new Thread(this, "GridLayEx2");
    imageThread.start();
    } // end of start method
    public void run(){
    Thread myThread = Thread.currentThread();
    while (imageThread == myThread) {
    repaint();
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e){ }
    }// end of run method
    public void paint(Graphics g){
    Font boldFont = new Font("Helvetica", Font.BOLD, 25);
    Font plainDerived =
    boldFont.deriveFont(Font.PLAIN, 25);
    JLabel myLabel[] = new JLabel[9];
    String myUrl = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\duke1.gif";
    myLabel[0] = new JLabel(new ImageIcon(myUrl));
    myLabel[1] = new JLabel("A");
    myLabel[2] = new JLabel("A");
    myLabel[3] = new JLabel("A");
    myLabel[4] = new JLabel("A");
    myLabel[5] = new JLabel("A");
    myLabel[6] = new JLabel("A");
    myLabel[7] = new JLabel("A");
    myLabel[8] = new JLabel("A");
    myLabel[1].setFont(boldFont);
    myLabel[2].setFont(boldFont);
    myLabel[3].setFont(boldFont);
    myLabel[4].setFont(boldFont);
    myLabel[5].setFont(boldFont);
    myLabel[6].setFont(boldFont);
    myLabel[7].setFont(boldFont);
    myLabel[8].setFont(boldFont);
    int values[] = new int[9];
    values = gen_pos_uni_ran_num(0,8);
    for(int i = 0; i < 9; i++)
    add(myLabel[values]);
    } // end of paint method
    public void stop(){
    imageThread = null;
    } // end of stop method
    public int[] gen_pos_uni_ran_num(int min, int max)
    int results[] = new int[Math.abs(max - min) + 1];
    for(int i = 0; i < results.length; ++i)
    results = -1;
    outer_loop:
    for(int i = 0; i < results.length; ++i)
    int random_int = (int)((Math.random() * results.length) + min);
    for(int j = 0; j < results.length; ++j)
    if(results[j] == random_int)
    random_int = (int)((Math.random() * results.length) + min);
    j = -1;
    continue;
    if(j == results.length - 1)
    results = random_int;
    continue outer_loop;
    return results;
    } // generate unique random numbers
    public static void main( String args[])
    Frame GridLayFrame = new Frame ( " Grid Layout Frame ");
    GridLayEx2 gl = new GridLayEx2();
    gl.init();
    GridLayFrame.add(gl);
    GridLayFrame.pack();
    GridLayFrame.setSize(GridLayFrame.getPreferredSize());
    GridLayFrame.show();
    GridLayFrame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    } // end of main method

    hi,
    i got one doubt in the previous application. i want to put labels in the circle manner while changing my label positions. Now it is rectangular type. And also i want to change my background color of JFrame. Please see my code ...
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.util.GregorianCalendar;
    public class GridLayEx6 extends JApplet{ 
       private Random r = new Random(); 
       private ActionListener taskPerformer;
       private javax.swing.Timer timer;  
       private GridLayout glt;  
       private JLabel[] myLabel;     
       GregorianCalendar todayDate = new GregorianCalendar();     
       long fromTime,toTime,elapsedTime;
       public void init() {     
            glt = new GridLayout(3,3);     
          Font boldFont = new Font("Helvetica", Font.BOLD, 25);     
          Font plainDerived = boldFont.deriveFont(Font.PLAIN, 25);     
             myLabel = new JLabel[9];     
             String myUrl = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\MyArrow.jpg";
             String myUrlA = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\MyA.jpg";     
             URL url = null;     
       try{
       myLabel[0] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);     
       myLabel[1] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[2] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[3] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[4] = new JLabel("+", SwingConstants.CENTER);     
       myLabel[5] = new JLabel(new ImageIcon(myUrlA), SwingConstants.CENTER);
       myLabel[6] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[7] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[8] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[2].setVerticalAlignment(SwingConstants.NORTH);     
       myLabel[4].setFont(boldFont);     
       getContentPane().setLayout(glt);     
      } catch( Exception e)
        { System.out.println(" Exception occurs "+e);}
       int delay = 20000; //milliseconds     
       ActionListener taskPerformer = new ActionListener() {     
       public void actionPerformed(ActionEvent evt) {      
                 randomDuke();
       timer = new javax.swing.Timer(delay, taskPerformer);     
       addKeyListener(new KeyAdapter()      {        
          public void keyPressed(KeyEvent e){           
                 GridLayEx6 gl2 = (GridLayEx6)e.getSource();           
                     switch(e.getKeyCode())
                           case(KeyEvent.VK_ENTER): 
                                gl2.randomDuke();                 
                                break;
                       case(KeyEvent.VK_SPACE):              
                            if(gl2.timer.isRunning())                    
                              { gl2.timer.stop();                 
                                    toTime = System.currentTimeMillis();
                                 elapsedTime = toTime - fromTime;
                                 System.out.println("toTime : "+toTime);
                                 System.out.println("elapsedTime : "+elapsedTime);
                                  gl2.timer.start();
                                   gl2.randomDuke();
                               break;
                       case(KeyEvent.VK_KP_RIGHT):case(KeyEvent.VK_KP_UP):              
                       case(KeyEvent.VK_RIGHT):case(KeyEvent.VK_UP):              
                         int delay = gl2.timer.getDelay();
                         if(delay > 0)                    
                            gl2.timer.setDelay(delay - 100);                 
                            break;
                       case(KeyEvent.VK_KP_LEFT):case(KeyEvent.VK_KP_DOWN):              
                       case(KeyEvent.VK_LEFT):case(KeyEvent.VK_DOWN):
                            int delay = gl2.timer.getDelay();                  
                            if(delay < 10000)                    
                                 gl2.timer.setDelay(delay + 100);                  
                                 break;
                       //timer.start();  
             } // end of init method  
             public void start()   {     
                  timer.start();     
                    while(!isFocusOwner())        
                            requestFocus(); 
             } // end of start method     
             public void stop(){    
                  timer.stop();
            } // end of stop method     
             /** To make sure we have focus in application *  
             * mode if JFrame loses focus control          *  
             * - non standard usage of paintComponent      */    
             public void paintComponent(Graphics g)   {
                  while(!isFocusOwner())        
                       requestFocus();  
            public void randomDuke()   {     
                  fromTime = System.currentTimeMillis();
                  System.out.println("fromtime : "+fromTime);     
                  getContentPane().removeAll();     
                  int[] values = new int[9];     
                  int temp;
                  values = gen_pos_uni_ran_num(0,8);     
                  for ( int i=0; i<=8;i++)
                          if ( values[i] == 4)
                                 temp = 4;
                                 values[i] = values[4];
                                 values[4] = temp;
                  for(int q = 0; q < 9; q++)   
                        getContentPane().add(myLabel[values[q]]);    
                       myLabel[0].revalidate();
                       myLabel[1].revalidate();
                       myLabel[2].revalidate();
                       myLabel[3].revalidate();
                       myLabel[5].revalidate();
                       myLabel[6].revalidate();
                       myLabel[7].revalidate();
                       myLabel[8].revalidate();
                    } // end of randomDuke method  
              public int[] gen_pos_uni_ran_num(int min, int max)   {     
                  int results[] = new int[Math.abs(max - min) + 1];     
                  for(int q = 0; q < results.length; ++q) 
                       results[q] = -1;     
                  outer_loop:     
                  for(int q = 0; q < results.length; ++q)  
                       int random_int = (int)((Math.random() * results.length) + min);        
                    for(int j = 0; j < results.length; ++j)       
                        if(results[j] == random_int)            {              
                            random_int = (int)((Math.random() * results.length) + min);              
                            j = -1;
                      continue;           
                     if(j == results.length - 1)
                          results[q] = random_int;              
                          continue outer_loop;
                  return results;  
                  } // generate unique random numbers  
                  public static void main( String args[])
                        JFrame GridLayFrame = new JFrame ( " Grid Layout Frame ");     
                       GridLayFrame.setSize(500,500);     
                       GridLayEx6 gl = new GridLayEx6();     
                       gl.init();     
                       GridLayFrame.getContentPane().add(gl);     
                       //GridLayFrame.setBackgroundColor(Color.white);
                       GridLayFrame.setVisible(true);
                       gl.start();     
                       GridLayFrame.addWindowListener(new WindowAdapter()      
                         public void windowClosing(WindowEvent e)         
                        System.exit(0);         }      });  
                  } // end of main method
                  }

  • Thread problems in Swing

    I'm building I guess its like an online strategy game. On the map, when you move your mouse to within 50 of the bounds of the applet, it'll start scrolling the map at a predetermined speed.
    When working with applets/painting/threads this worked like a dream. Java was too fast for itself and I had to even slow the scrolling down.
    Now, I'm building the whole thing in swing instead. The map is technically a JLabel inside of a Container that gets loaded into the main contentPane.
    The only way I could use setLocation in my threads run method was to setLocation on the Container, not the JLabel. Odd fix to that problem. (I kept getting a null pointed exception otherwise)
    My problem is, when the mouse is in that 50 pixels, the program knows it, but it just /lags/. Horribly. I set a counter to print to the console and when the mouse enters the area it moves to like 15 (in 0.001 seconds), and stops. I move my mouse around, and a few seconds later I see 700-705, then it stops, and jumps ahead again if I move my mouse.
    So my program will now scroll the map in very small, /very/ jagged bits.
    It's not an intensive program or code. I don't see how or why the thread can't continually run it.
    My run method:
    public void run() {
              while (true) {
                   if (mouseX > 650 && mouseX <= 700)
                        moveRight = true;
                            if (moveRight == true) {
                        if (mapCurrentX + screenX < (xDimension)) {
                             mapCurrentX -= moveSpeed;
                             contentPane.setLocation(mapCurrentX, mapCurrentY);
                   try {
                        // Stop thread for 20 milliseconds
                        Thread.sleep(20);
                   catch (InterruptedException ex) {
                        // do nothing
                   Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
         }

    I got this when I ran it ^_^;; Gonna try to fix it
    Wrong Thread
    java.lang.Exception: Stack trace
         at java.lang.Thread.dumpStack(Unknown Source)
         at ThreadCheckingRepaintManager.checkThread(ThreadCheckingRepaintManager.java:13)
         at ThreadCheckingRepaintManager.addInvalidComponent(ThreadCheckingRepaintManager.java:6)
         at map.<init>(map.java:74)
         at ClientMain3.init(ClientMain3.java:12)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

  • Thread Problem while executing jar

    Actually I have one thread working in swing components (type SwingWorker). When I try to run it by pressing a button, it works fine for a minute or 20 seconds, than it shut itself off.
    When you debug you project in an IDE everything is fine, everything is working. But in jar file it does not work. What may cause this problem?
    Any idea?

    I changed my code already but I can try to show you what I want to do;
    public class SenCollThread implements Runnable
        private Collector collector;
        private Database database;
        private List<String> verbList;
        public SenCollThread (int index,List<String> verbList)
            this.verbList = verbList;
            this.index = index;
            generator = new VerbGenerator ();
    //Internet Communication, download and file  operation
            collector = new Collector ();
    //Internet Communication, download and file  operation
    //MySql Connection made in constructor
            database = new Database ();
    //MySql Connection made in constructor
    public void run()
        for(int i=index; i < verbList.size(); i++)
           database.insert(collector.collect(i,verbList.get(i)));
    public class Collector
       public String Collect()
          synchronized(this)
             String text = //make net connection ad download
             return text;
          return null;
    public class Database
    private Connection conn;
    public Database()
        conn = //create mysql connection
    public void Insert(String text)
         try
            synchronized(this)
                 //Insert database
        catch(){
    int void main()
        List<String> verbList = getVerbList(); // returns a synchronized list
        List<Integer> startIndex = getIndexList();
        List<Thread> threadList = new ArrayList<Thread>();
          for(int i=0; i < 3; i++)
              SenColThread sencol = new Sencol(startIndex.get(i).intValue(),verbList);
             Thread thread = new Thread(sencol);
             threadList.add(thread);
             thread.start();
        while(true)
            int stopCount = 0;
             for(int i=0; i < threadList.size(); i++)
                 if(!threadList.isAlive()) stopCount++
           if(stopCount == (threadList.size() -1))
                   break;
    }Actually I did logging but all I saw is Threads Are Stopped Successfully. This happens after first sencol created and ran, and it downloads its first data from net, but then eveything stops. No other threads starting.

  • Thread problem.. help

    I have a thread execution of my program which reading a text file and in the same time giving the priority to the GUI.
    My problem is, if I comment the:
          m_Support.firePropertyChange("", null, null);in the method "setWorkingInstances", my GUI will display the content of the file, otherwise if it's uncomment, my GUI is processing something, and never displays the output but busy. Can anybody help me to solve this problem? I'm headache of this..
    m_Support is the object that tells another class that the owner of the m_Support propertychange has been invoked (i hope i'm rite).
    public void setBaseInstancesFromFile(final File f) {
        if (m_IOThread == null) {
          m_IOThread = new Thread() {
            public void run() {
              try {
                Reader r = new BufferedReader(new FileReader(f));
                // call the function
                setBaseInstances(new Instances(r));
                r.close();
              catch (Exception ex) {
                //..bla..
              m_IOThread = null;
          m_IOThread.setPriority(Thread.MIN_PRIORITY); // GUI has most priority
          m_IOThread.start();
        } else {
          //..bla..bla..
    public void setBaseInstances(Instances inst) {
        m_BaseInstances = inst;
        try {
          Runnable r = new Runnable() {
            public void run() {
              ... bla.. bla..
              // call again another function
              setWorkingInstances(m_BaseInstances);
          if (SwingUtilities.isEventDispatchThread()) {
            r.run();
          } else {
            SwingUtilities.invokeAndWait(r);
        } catch (Exception ex) {
           ..bla.. bla..     
    public void setWorkingInstances(Instances inst) {
        if (m_WorkingInstances != inst) {
          m_WorkingInstances = inst;
          ... bla.. bla.. bla..     
          // Fire a propertychange event
          m_Support.firePropertyChange("", null, null);
      }

    This seems kind of a strange way of doing things... but maybe I misunderstand what you are trying to do.
    Here's what I think you are trying to do:
    Read a file in a worker thread
    While the worker thread is running, send update notifications to GUI objects in the Swing GUI thread.
    Is that correct?
    If so, then all you have to do is start the worker thread from the Swing GUI thread, then have the worker thread send periodic notifications to the GUI object - let's say in a method called textContentsChanged().
    In textContentsChanged, you would then wrap up the notification into a simple Runnable object, and pass it in to invokeAndWait().
    Is that what you are trying to do??
    - K

  • SQL query / thread problem!

    I have the following code. when the execute mkethod is called, an instance of TransactionRunner is created. within the run method of TransactionRunner an SQLQuery is executed. I want to return the result set when the query has been executed, how can I do this, at the moment it tries to return the resultSet before the thread has finished. any ideas? I hav tried using a boolean as a flag but it doesn't appear to work.
    public static ResultSet execute(String SQL, boolean rs)
    System.out.println("in execute, dbm") ;
    SQLStatement = SQL ;
    result = rs ;
    complete = false ;
    tr = dbm.new TransactionRunner(SQL) ;
    //SOME FORM OF INDICATION TO THE END OF SQL EXECUTION
    return resultSet ;
    class TransactionRunner implements Runnable
         public ResultSet rs ;
         private Thread queryThread ;
         public String SQLStatement ;
         public TransactionRunner(String SQL)
              SQLStatement = SQL ;
              queryThread = new Thread(this) ;
              queryThread.start() ;
         public void run()
              if (result == true)
                   executeQuery(SQLStatement) ;
                   complete = true;
              else
                   update(SQLStatement) ;
              }

    I am up against the same problem, but I believe that
    you could fire off a progress monitor during the
    thread task and have the thread return the ResultSet.If you're planning to use Swing, then yes, you do need to execute the command in a spawned thread, otherwise your event thread will hang. BUT, spawning a sub-thread from a Swing app is not equivalent to spawning one from a simple console app, because the Swing event thread will keep your process alive. Instead, I would suggest doing something like the following:
    1) In the ActionListener that invokes the query (may be hung off a menu item, or a button, depending on your app):
            public void actionPerformed(ActionEvent actionEvent)
                (new Thread(new MyQuery())).start();
                displayWaitIndication();
            }This method runs in the event thread, and spawns a sub-thread to run the query. It also displays some sort of wait indication, maybe a progress box or a WAIT_CURSOR (I prefer the wait cursor, as you can't accurately display the progress of a server-side operation).
    2) MyQuery implements Runnable:
            public void run()
                List data = // call something to perform DB op here
                SwingUtilities.invokeLater(new Runnable()
                    public void run()
                        mainWindow.refresh(data);
            }This may be a bit confusing, as it leaves a lot of stuff out. I've used "List" as the return from the database function; chances are that you'll actually implement something like MyResultSet. You don't want to use an actual java.sql.ResultSet, because it (may) perform(s) a client-server call to retrieve each row. So, you process the real result-set into a container object (List or whatever) in the sub-thread.
    Then, you pass that container object back to the display window, on the event thread. I've used a variable to access the display window; you may do things differently. The key thing is the use of SwingUtilities.invokeLater(), to perform the actual update on the event thread.
    To summarize:
    1) You initiate the action on the event-thread.
    2) You perform the action in a sub-thread, put the resuls into a container.
    3) You update your display on the event-thread, using SwingUtilities.invokeLater().

  • Sun Java System Web Server 6.1 SP3 service-j2ee threads problem

    Hi,
    Sorry my english.
    I'm an intermediate Java programmer and a newbie in
    the Sun's web servers world.
    I'm doing an evaluation of an web applicaction
    written in Java Servlets that is
    supposed to have a leaking threads problem. We use
    SunOS 5.9 (... sun4u sparc SUNW,UltraAX-i2) and
    JVM 1.5 Update 4 (the problem is presented too
    in SunOS 5.8 and JVM 1.4.2_04).
    We have seen, thanks to 'prstat' (PROCESS/NLWP) a
    increasing thread's growing in one of the process
    that correspond to our web server instance (I'm sure I'm
    looking the right process). I have checkout the source
    code and it seems like the app doesn't have threads
    problems. I have used the Netbeans Profiler and I see a
    high number of threads called service-j2ee-x that grows
    in congestion moments and never disappear.
    Anybody could help me with suggestions?
    Thank you very much.

    Elvin,
    Thankyou, yes I am unfamiliar with debugging Java apps. I got the web server Java stack trace and I have passed this on to the developer.
    The web server finally closes the socket connection after the total connections queued exceeds 4096.
    There are several hundred entries like this... waiting for monitor entry.. could be a deadlock somewhere?
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "service-j2ee-506" prio=5 tid=0x04b62a08 nid=0x17a waiting for monitor entry [dd74e000..dd74f770]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.util.JSDispenser.getConnResource(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting to lock <0xe979b2b0> (a com.verity.search.util.JSDispenser)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.getDoc(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.getDoc(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.docViewIntern(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.docView(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at au.com.relevance.viewDoc.PdfXmlServlet.performRequest(PdfXmlServlet.java:120)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at au.com.relevance.viewDoc.PdfXmlServlet.doGet(PdfXmlServlet.java:141)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at javax.servlet.http.HttpServlet.service(HttpServlet.java:787)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at javax.servlet.http.HttpServlet.service(HttpServlet.java:908)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:771)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:322)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:209)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:161)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[highlight]" daemon prio=5 tid=0x000f3530 nid=0x1e waiting on condition [e15ff000..e15ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[highlight]" daemon prio=5 tid=0x000f3328 nid=0x1d waiting on condition [e16ff000..e16ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[]" daemon prio=5 tid=0x000f2b08 nid=0x1c waiting on condition [e1b7f000..e1b7fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[]" daemon prio=5 tid=0x000f2900 nid=0x1b waiting on condition [e1c7f000..e1c7fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[sitesearch]" daemon prio=5 tid=0x000f1cd0 nid=0x1a waiting on condition [e23ff000..e23ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[sitesearch]" daemon prio=5 tid=0x000f1ac8 nid=0x19 waiting on condition [e24ff000..e24ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[search]" daemon prio=5 tid=0x000f0a88 nid=0x18 waiting on condition [e317f000..e317fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Signal Dispatcher" daemon prio=10 tid=0x000ef840 nid=0x12 waiting on condition [0..0]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Finalizer" daemon prio=8 tid=0x000ef638 nid=0x10 in Object.wait() [fa27f000..fa27fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting on <0xe917fb10> (a java.lang.ref.ReferenceQueue$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - locked <0xe917fb10> (a java.lang.ref.ReferenceQueue$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Reference Handler" daemon prio=10 tid=0x000ef430 nid=0xf in Object.wait() [fa37f000..fa37fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting on <0xe917fb78> (a java.lang.ref.Reference$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Object.java:429)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - locked <0xe917fb78> (a java.lang.ref.Reference$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "main" prio=5 tid=0x000ee3f0 nid=0x1 runnable [0..ffbff200]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "VM Thread" prio=5 tid=0x004ee328 nid=0xe runnable
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "VM Periodic Task Thread" prio=10 tid=0x004ee5d0 nid=0x16 waiting on condition
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Suspend Checker Thread" prio=10 tid=0x004ee548 nid=0x11 runnable
    [15/May/2006:22:15:10] failure ( 3196): HTTP3287: connection limit (4096) exceeded, closing socket

  • Cant syncronize! Threads problem

    Hello everybody,
    recently i posted a question(im new to threads) and it was asked immediately but now i have another
    type of problem.
    Please read here the initial post and the answer and please give me any ideas..
    Initial Post
    Hi everybody,i have this thread problem(i'm new to java and h
    ave no idea what exactly to do).
    Well,in my applet i have this action performed method
    that i imagine is in the event dispatch thread.
    This method calls as u see, two other methods of a class named CPU(.
    Note that fetch and execute are observed classes and my applet class
    is the observer.
    The problem is that during the execution of fetch() and execute(),
    inside these methods change some things and so they call notifyObservers(Object arg)
    passing to the applet the argument and so the applet updates some text components.
    But as you can immagine there is no time for the gui to update himself so i see nothing.
    So, my question is which of the methods need to be in a separate thread so to ensure
    visible results(component updating)?
    Perhaps,the update method needs to be invokedLater with SwingUtilities?
    Please give me an example code if possible.
    Here is the actionPerformed code(from the applet class) and the fetch method:
        void executeProgramButton_actionPerformed(ActionEvent e) {      
    int numInstr = this.machine.ram.segmentSize;       
    for (int i = 0; i < numInstr; i = i + 4) {           
    machine.cpu.fetch();           
    machine.cpu.execute();       
    /*The following method is in the CPU class
    fetch method:here the observedPC is the observable value
    that notifies the observer(the main applet)
    that does: pcTextField.setText(arg.toString());*/   
    public void fetchInstructionProgram() {       
    observedPC = Integer.toString(pc);       
    setChanged();       
    notifyObservers(observedPC);       
    instructions++;       
    instruction=readOperation(cache.instructionfetch,pc);       
    pc = pc + 4;    }
    Answer to initial post
    Author: stevejluke
    One way could be to put the content of the action performed method into a new thread, then use invokeLater in your Observers that cause GUI updates:
        void executeProgramButton_actionPerformed(ActionEvent e) {     
    new Thread()       {      
    public void run()        {         
    int numInstr = this.machine.ram.segmentSize;         
    for (int i = 0; i < numInstr; i = i + 4)           {           
    machine.cpu.fetch();           
    machine.cpu.execute();         
    }.start();    }
    // In your Observer    public void update(Observable o, Object arg)    {     
    SwingUtilities.invokeLater(new Runnable() {      
    public void run()        { 
    /* your GUI afecting code
    });[i]
    Or something like that.
    You might need to watch for synchronizing things
    He was right...GUI is responsive but the results...
    Well,let me describe the new problem.
    Here you cant see the method execute().
    The problem is a synchronization problem.
    Actually,what the two methods do is:fetch() updates the value of a long called instruction and execute() takes this value and do some things.Note also that the time the execute method needs to finish is not
    always the same.By that, i mean that it depends on the value of the instruction updated by fetch().
    By putting some System.outs before and after updating i realized that there are delays or sometimes
    i noticed that fetch() executes 2 times before execute() takes control.
    So,i created some synchronized private methods set and get to control access to these resources.
    Better but still not correct...
    What should i look?Where stays the answer?
    How to synchronize these two methods on these resources?
    Thank you in advance,
    Chris

    I think that your fetch and execute has a "Producer-Consumer Relationship"
    in such cases you can make the producer place the produced value in to a queue and consumer take the vlues from the queue
    In the producer thread it sleeps for a while and try again if the Queue is full
    In the Consumer thread it sleeps for a while if the Queue is empty and then try again
    Or you can do as follows
    In the Producer thread it waite() if the Queue is full
    In the Consumer thread it waite() if the queue is empty
    When ever Producer put a value in to the Queue it calls the notify on Consumer and when ever Consumer takes a value from Queue it calls the notify() on Producer
    you can even use notify all
    I think thiere is no built in Queue class in java so you will have to write one here is a example
    public class MyLongQueue{
                long data[];
                int head, tail;
                int size;
               public MyLongQueue(int size){
                    data = new long[size];
                    head = -1;
                    tail = -1;
                    this.size = 0;
                public synchronized boolean isFull(){
                    return (size==data.length);
                public synchronized boolean isEmpty(){
                    return (size==0);
                public synchronized boolean  insert(long l){
                    if (size==data.length) return false; //Queue is full cant add more data
                    tail = (tail + 1) % data.length;
                    data[tail] = l;
                     size++;
                    return true;
               public synchronized long remove(){
                   if (size==0) throw new ArrayIndexOutOfBoundsException();
                   size--;
                   head = (head + 1) % data.length;
                   return data[head];

  • JNI & thread problem

    Folks,
    I am using JNI to access WIA (Windows Image Acquisition) functionality under MS Windows XP. WIA consists of a bunch of COM interfaces. I have several native functions in a single dll, with a limited number of static variables stored in the dll between calls. This all works fine as long as long as the calls occur from the same java thread, but not if a new thread is created for some of the calls. I.e., this works:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    but this does not:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    (new Thread() {
    public void run() {               
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    }).start();
    Here, initializeWIA() and transferJPGNative() are the native methods. What happens in the second case is that transferJPGNative fails in one of the COM methods (not the first COM method it calls). The COM method returns an HRESULT indicating an error (509) which I can't find using any of the usual MS error look-up mechanisms. (Admittedly I am not the world's greatest Windows programmer...)
    Anyway, any suggestions would be much appreciated. I have found some issues regarding JNI and threads in this forum's archives, but none of them seem to apply to quite this situation.

    As a guess this is just a windows threading problem.
    And with COM you have to do things differently (I believe) if there is more than one thread. You might not even be allowed to do it with for that particular API.
    It could also be that you are initializing things more than once. Or you need to initialize twice (two handles.)
    At any rate you could always fix it by making the java code only allow calls for a single thread.

  • Urgent!!!!!!!HANDLER THREAD PROBLEM

    file name GetName.html
    <html>
    <body>
    <FORM METHOD = POST ACTION = "SaveName.jsp">
    what is your name?
    <INPUT TYPE = TEXT NAME=username SIZE= 20>
    <p><INPUT TYPE= SUBMIT>
    </FORM>
    </BODY>
    </HTML>
    file name SaveName.jsp
    <%
    String name = request.getParameter( "username" );
    session.setAttribute( "theName", name );
    %>
    <HTML>
    <BODY>
    Continue
    </BODY>
    </HTML>
    file name NextPage.jsp
    <html>
    <body>
    Hello, <%=session.getAttribute("theName") %>
    </body>
    </html>
    when I try to execute , SaveName.jsp is generating the following error message. what is the problem? I am using jswdk. please help. I have included tools.jar in classpath. what could be the problem?
    Unhandled error! You might want to consider having an error page to report such
    errors more gracefully
    com.sun.jsp.JspException: Compilation failed:Note: sun.tools.javac.Main has been
    deprecated.
    work\%3A8080%2Fexamples\SaveName_jsp_1.java:71: Method setAttribute(java.lang.St
    ring, java.lang.String) not found in interface javax.servlet.http.HttpSession.
    session.setAttribute( "theName", name );
    ^
    1 error, 1 warning
    at com.sun.jsp.compiler.Main.compile(Main.java:347)
    at com.sun.jsp.runtime.JspLoader.loadJSP(JspLoader.java:135)
    at com.sun.jsp.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspS
    ervlet.java:77)
    at com.sun.jsp.runtime.JspServlet$JspServletWrapper.service(JspServlet.j
    ava:87)
    at com.sun.jsp.runtime.JspServlet.serviceJspFile(JspServlet.java:218)
    at com.sun.jsp.runtime.JspServlet.service(JspServlet.java:294)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
    at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
    at com.sun.web.core.Context.handleRequest(Context.java:414)
    at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)
    HANDLER THREAD PROBLEM: java.net.SocketException: Socket is closed
    java.net.SocketException: Socket is closed
    at java.net.Socket.getInputStream(Socket.java:643)
    at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)

    Are you using JSWDK 1.0.1? If you are, then the implementation uses the Servlet Spec. 2.1. The set/getAttribute methods were added in 2.2.
    Try using the now-deprecated method putValue like this in SaveName.jsp.
    <%
    String name = request.getParameter( "username" );
    session.putValue( "theName", name );
    %>

  • Thread problems with Samsung D500? Http or https troubles?

    Hi!
    I've got some troubles with my application installed onto my D500, and I suspect that's maybe thread problem.
    Does anyone know something about thread problems for this phone?
    I want to know, is there any trouble for connecting application by using http or https?
    I've found one problem for E720 - it escapes "backslash" character when it's used as http parameter.
    It makes parsing troubles...
    Did anyone have some similer troubles, and how have you solved this problem?
    Thanks in advance,
    Alex

    When I'm trying to connect to the net by using my application, I get two errors: "TCP open" and "interruptedIOException", and so I suspect that's some kind of thread problems.
    On the other phones (Nokia, Sony Ericsson) this application works with no problems...

  • The Single Threaded Nature of Swing

    I am designing a program that uses the basic <i>Model View Controller</i> design pattern. The controller allows you to manipulate the <i>Model</i> and the <i>Views</i> then display a graphical representation of the <i>Model</i>.
    Any way I want to have several different, independent <i>Views</i> of my <i>Model</i>. So I thought; well since the <i>Views</i> are only dependent on the <i>Model</i> I should be able to have the <i>Model</i> raise an event to alert the <i>Views</i> to update their drawing appropriately. Naturally since all the <i>Views</i> are independent I would like them to draw in their own threads, but since Swing is not thread safe it seams that i wont be able to do that.
    As a potential solution I am considered having each <i>Views</i> first create a graphics object that has all the new drawing information, then make a call to repaint through Swings Event Dispatch Thread and and have the component paint method simply BLIT from the pre-rendered graphics object into the graphics Object passed in the paint method. This has the advantage of allowing all the <i>Views</i> to do their drawing code concurrent;y and keep the <i>Controller</i> portion responsive since the even dispatch thread will only have to perform a very simple operation for repaints, however since i have no guarantee as to when the Event Dispatch Thread will actually get around to drawing them I winder if latency will be an issue.
    Non the less I can't help but think that in such a situation it would be safe to multi-thread the drawing. I would like to know if any body else has had to do something similar and what kind of approach they took.
    Flaws in my logic or comments regarding my current solution are also greatly appreciated.

    PCP wrote:
    Any way I want to have several different, independent <i>Views</i> of my <i>Model</i>. So I thought; well since the <i>Views</i> are only dependent on the <i>Model</i> I should be able to have the <i>Model</i> raise an event to alert the <i>Views</i> to update their drawing appropriately. Which is how Swing components work internally, so it all sounds good here.
    Naturally since all the <i>Views</i> are independent I would like them to draw in their own threads, but since Swing is not thread safe it seams that i wont be able to do that.It almost sounds as if you are confusing thread safety with not having the ability to interact with different threads. I'm no Graphics expert, but I think that Swing can handle all this as long as you handle Swing right: Do what you need to do in your separate threads, but just remember to only update Swing components on the EDT.
    As a potential solution I am considered having each <i>Views</i> first create a graphics object that has all the new drawing information, Or perhaps a graphics object derived from a BufferedImage object?
    then make a call to repaint through Swings Event Dispatch Thread and and have the component paint method simply BLIT from the pre-rendered graphics object into the graphics Object passed in the paint method. This has the advantage of allowing all the <i>Views</i> to do their drawing code concurrent;y and keep the <i>Controller</i> portion responsive since the even dispatch thread will only have to perform a very simple operation for repaints, however since i have no guarantee as to when the Event Dispatch Thread will actually get around to drawing them I winder if latency will be an issue.What is the frequency with which you are calling repaints? Have you tried this and found that Swing degrades your program's responsiveness? Again, I'm no graphics expert (where's Darryl, Hiwa, Morgalr when you need them?), but have you considered using active rendering instead of the typical passive rendering?
    Non the less I can't help but think that in such a situation it would be safe to multi-thread the drawing. I would like to know if any body else has had to do something similar and what kind of approach they took. Flaws in my logic or comments regarding my current solution are also greatly appreciated.Whatever happens, please let us know the outcome. Good luck!

  • HANDLER THREAD PROBLEM?

    I'm trying to use the method Response.sendRedirect to forward users to another website. The actual case is irrelevant so I've extracted the important part into a simple servlet example:
    import javax.servlet.http.*;
    import java.io.*;
    public class ReDirect extends HttpServlet
       public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
          if(req.getQueryString()!=null)
             res.setContentType("text/html");
             res.getWriter().println("Your querystring: <b>"+req.getQueryString());
          else
             res.sendRedirect("http://java.sun.com");
    }The funny thing is that the servlet works FINE, but that darn thing is generating an IOException (showing in the DOS prompt of the webserver) everytime the sendRedirect method is called! Why?
    ReDirect: init
    HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
    java.io.IOException: Socket Closed
         at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:432)
         at java.net.Socket$1.run(Socket.java:335)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.Socket.getInputStream(Socket.java:332)
         at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)I have tried everything... I've also searched the forum for similar problems, but it seems that noone have a logic explanation for this. Is this a bug in the servlet engine or is it something I'm doing wrong or have forgotten?
    I'm using jswdk 1.0.1 and jdk1.3.1 on windows 2000, running the webserver that comes with jswdk.
    Please, someone, explain this to me! This problem is torturing me day and night!!
    /Stefan Westling

    Go get tomcat ...I used to get this error lot's when I used the jswdk. There are just some things it doesn't like ...yet when structured in certain way's ...it would work. I never did track down any consistent explanation. I just moved on to tomcat. The jswdk is really cheesy ...it can't do post ...or sessions ...or any 2.0 functionality ... or ... or ... Go get tomcat.

  • Problem with threads in my swing application

    Hi,
    I have some problem in running my swing app. Thre problem is related to threads.
    What i am developing, is a gui framework where i can add different pluggable components to the framework.
    The framework is working fine, but when i press the close action then the gui should close down the present component which is active. The close action is of the framework and the component has the responsibility of checking if it's work is saved or not and hence to throw a message for saving the work, therefore, what i have done is that i call the close method for the component in a separate thread and from my main thread i call the join method for the component's thread.But after join the whole gui hangs.
    I think after the join method even the GUI thread , which is started for every gui, also waits for the component's thread to finish but the component thread can't finish because the gui thread is also waiting for the component to finish. This creates a deadlock situation.
    I dont know wht's happening it's purely my guess.
    One more thing. Why i am calling the component through a different thread, is because , if the component's work is not saved by the user then it must throw a message to save the work. If i continue this message throwing in my main thread only then the main thread doesnt wait for user press of the yes no or cancel button for saving the work . It immediately progresses to the next statement.
    Can anybody help me get out of this?
    Regards,
    amazing_java

    For my original bad thread version, I have rewritten it mimicking javax.swing.Timer
    implementation, reducing average CPU usage to 2 - 3%.
    Will you try this:
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    public class SamurayClockW{
      JFrame frame;
      Container con;
      ClockTextFieldW ctf;
      public SamurayClockW(){
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        con = frame.getContentPane();
        ctf = new ClockTextFieldW();
        con.add(ctf, BorderLayout.SOUTH);
        frame.setBounds(100, 100, 300, 300);
        frame.setVisible(true);
        ctf.start();
      public static void main(String[] args){
        new SamurayClockW();
    class ClockTextFieldW extends JTextField implements Runnable{
      String clock;
      boolean running;
      public ClockTextFieldW(){
        setEditable(false);
        setHorizontalAlignment(RIGHT);
      public synchronized void start(){
        running = true;
        Thread t = new Thread(this);
        t.start();
      public synchronized void stop(){
        running = false;
      public synchronized void run(){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try{
          while (running){
            clock = sdf.format(new Date());
            SwingUtilities.invokeLater(new Runnable(){
              public void run(){
                setText(clock);
            try{
              wait(1000);
            catch (InterruptedException ie){
              ie.printStackTrace();
        catch (ThreadDeath td){
          running = false;
    }

  • Multiple Threads Problem

    Hi,
    I am new to Java Threading and the current program that I am working is having problems. The program basically paints lines and dots or onto a JPanel which displays an image. There exists a thread here to suspend and resume the drawing at the user's disposal. This part works flawlessly.
    Now since the images are quite large I have attempted to add a JWindow to the JFrame to indiate that the image is loading. And here lies my problem, the JWindow which also contains a paint method does not display anything until after the image is fully loaded onto the JPanel.
    Can someone please tell me what I am doing wrong and how to implement this?
    Thanks, James
    Here is how my program is structured:
    public class Proj extends JFrame
    public Proj()
    Display disp = new Display();
    Thread thr1 = new Thread(disp);
    thr1.start();
    Container con = getContentPane();
    con.add(vsr);
    setSize(500,500);
    show();
    public static void main(String [] args)
    {  new Proj();
    class Display extends JPanel implements Runnable
    public Display()
    Loading ld = new Loading();
    Thread thr2 = new Thread(ld);
    ld.start();
    // gets data and image files
    ld.interrupt();
    public void paintComponent(Graphics g)
    // draws image, lines, circles etc.
    public void run()
    // involved with data to draw next image, lines etc.
    class Loading extends JWindow implements Runnable
    public void paint(Graphics g)
    // displays loading animation
    public void run()
    // animation code

    Since Swing is single-threaded, any painting activity after a component is realized/visible should be handled on the EDT (Event Dispatch Thread). The loading of data/files can be done on worker different thread. On the EDT you should fetch the status and paint your progress bar. If you paint the progress bar on the worker thread it would not work out the way you want. Try to also investigate into SwingUtilities.invokeLater method which allows us to put a code to be executed on the EDT.

Maybe you are looking for

  • Satellite L300D boots into a blank screen with mouse cursor

    Hi, I have been asked by friends of mine to help them fix their L300D. Their son got to it and they are not sure what he did, but now when it loads into VIsta, all they get is a Black Screen with a mouse cursor in the middle. The cursor looks as if i

  • How to save a PDF File if you create it in lifecycle and view it in adobe reader 9.

    I am having a issue with a file that I created in Adobe lifecycle and then tried to fill out the form in adobe reader 9. Here is the big issue I can fill out the form but can not save the information that I put in the form. It will only allow me to s

  • Acrobat 8 can't locate scanner to create PDF from printed document using OCR

    Hello, I have an Epson scanner that is my default scanner on my OSX (10.6).  Every program I have locates my scanner perfectly except Acrobat 8.0.  Is there something I can do? From the home dialogue box I click "Create PDF from Scanner".  The next d

  • Filter logic

    HI all, I am saving the layout with filter. My requirement is when we run the report , the excel should come as per filter in  the layout. Before comeing to 'reuse_alv_grid_disaply', my excel sheet is coming to my inbox. . Filter is woking in report

  • Dedupe a comma list

    I have a string of values in a comma delimited list. Is there a quick and easy way to find exact duplicated and remove all but one? I am sure I could sit down and come up with CFLOOP/IF-fest but wondered if there was already something out there.