Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get result back from a thread?  RSS feed

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am Chaitanya, I am working on a billing application where there is a swing window which accepts the product details then adds it to the database.

I spawned a new thread to add the details to the database. The method which adds record to the database returns a message if there is any error, such as trying to add product id which has been already taken.

How to get back the result to my frame window so that I can display the error message.

Code snippets:
Jframe code:

Model code:

Can anyone help me fix it? Thank you all in advance. Have a good day.
 
Stephan van Hulst
Saloon Keeper
Posts: 7003
110
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look at the java.util.concurrent.Callable interface.

You can execute Callables using an ExecutorService, which you can create using the java.util.concurrent.Executors class.
 
sarvesh meens
Ranch Hand
Posts: 43
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Callable will get the work done.
Since you are using Swing, take are look at SwingWorker as well. It is specifically designed for the kind of problem you are encountering now.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!