library event handler threads
Hi
I am creating a small class-library for my own projects involving some heavy IO operations. We all know this take some time and therefore should not happen on the GUI thread. My library therefor start a new thread when it start working, but my question is; Should I code so that the library automaticly does the SwingUtils.invokeLater internally or is this something that should be done by the user of the library? Or is there any other (better) way to make sure the events triggered during the library actually happens inside the GUI thread? Want to avoid possible concurrency problems and race conditions, but on the other hand, I may use this library without using swing.
The code for the library (am just writing some architecture as I havent starting writing the actual code yet) may look like this:
interface someeventlistener
{
publicvoid eventtriggered();
}
class Libraryimplements Runnable
{
private Vector<someeventlistner> listeners =new Vector<someeventlistener>();
public Library()
{
(new Thread(this)).start();
}
publicvoid run()
{
while(alot_of_operations_isnt_finished)
{
do_some_processing();//just to explain
trigger_library_events();
}
}
privatevoid trigger_library_events()
{
for(int i=0;i<listeners.size();i++)
((someeventlistener)listeners.get(i)).eventtriggered();//should this be inside invokeLater ?
}
publicvoid addEventListener(someeventlistener e)
{
listeners.add(e);
}
}
PS: This may or may not be posted wrong. I thought it had more to do with concurrency than swing/gui, but maybe I am mistaken?>

