Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Application using thread freezes :(

Thread view: 
Vojta - 12 Mar 2006 17:35 GMT
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);
       }
}
Martin Gregorie - 12 Mar 2006 22:15 GMT
> Hello!
>
[quoted text clipped - 4 lines]
> 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.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Vojta - 13 Mar 2006 15:59 GMT
Hello Martin,

thank you a lot for your advice! Vojta

>> Hello!
>>
[quoted text clipped - 23 lines]
> Swing's event dispatching thread, which side-steps the writelocking
> problem.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.