Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

asynchronous threads and user feedback  RSS feed

 
Patty Fernandez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the correct pattern to use for user feedback when a service thread fails? Does each asynchronous sub thread typically throw the exceptions up or does one apply listeners?

Take my example:

I have a user interface which on an asynchronous thread creates a new multi cast connection, and then listens to the connection for incoming messages. The multi cast connection also has its own asynchronous threads for sending and receiving of data. If I have an exception (i.e. unknown hosts or ioexceptions) can I throw them back up to the user interface thread? Is there a better pattern?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Patty,

Welcome to JavaRanch!

You generally can't throw exceptions "at" or "to" other threads; it doesn't really work like that. But your application can have a central error-logging facility (i.e., an object with a "reportError(String msg)" method) and you can make sure each of your threads has access to it, and then when they have an error, they can call that method. That method, in turn, would do whatever is necessary to report the error. In a desktop app, it might report the error with a JOptionPane; in a Web app, it might simply store the error message to be retrieved by a periodic page refresh.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!