Application using thread freezes :(

V

Vojta

Hello!

I have a thread that goes through directories and stores filenames found
into a file. I also have a frame (JFrame) with text field (JTextField). When
the thread is running the text field shows which directory is currently
beeing processed. It works great until I try to make a selection with mouse
inside the text field. Application freezes immediatelly. Please, what have I
done wrong?

Thank you! Vojta

The frame implements my ThreadListemer interface...

public interface ThreadListener {
void ThreadStarting(Thread t);
void ThreadEnding(Thread t);
void ThreadProgressChanging(Thread t);
}

.... and defines it's abstract methods. I was experimenting with method
ThreadProgressChanging which is responsible for updating text field but the
problem still persists.

public void ThreadProgressChanging(Thread t) {
synchronized(jTextField1 ) {
jTextField1.setText(((FileScannerThread)t).currentPath);
}
}
 
M

Martin Gregorie

Vojta said:
Hello!

I have a thread that goes through directories and stores filenames found
into a file. I also have a frame (JFrame) with text field (JTextField). When
the thread is running the text field shows which directory is currently
beeing processed. It works great until I try to make a selection with mouse
inside the text field. Application freezes immediatelly. Please, what have I
done wrong?
You might have run into the same problem I saw with a JTextArea. They
both have an underlying Document so this quite possible.

Gory details are in my earlier post today that was about Swing
performance issues.

Like you, I was using a worker Thread to update the JTextArea. I also
have a KeyListener to grab key strokes and pass them into my model
object, but every so often, while I was typing, the application would
report a failure to get a writelock on the Document, stack dump and
freeze, though its menu bar still worked to exit from it.

The solution in my case was to rewrite the worker thread as a
javax.swing.Timer. The worker thread's repeated action was turned into
an ActionListener.actionPerformed() method which is fired by the
javax.swing.Timer. The effect is to execute the actionPerformed() code
in Swing's event dispatching thread, which side-steps the writelocking
problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top