Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

probelms in thread

 
Karthikeyan Mogan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to contact a class which uses thread to process . The java class mainly contacts the database and gets me the result set. Say i will be contacting the java class which uses a thread for twice and the main thread needs to print the result returned by the java class. The main thread is the servlet . How to do this ? If i try to make the servlet to wait Exception occurs and if i try to retrive the result set in the servlet i am can get only the empty result set.

I am using a array of resultset in the java class. Suggest me a way how to process this. I need to obtain the result set from the java class in the main Thread that is in the servlet once the 2 threads have completed its execution .
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the code into an ordinary Java application and get it working first. (My guess: Right now it doesn't work there either.) Then once it is working, put the code into your servlet.
 
Karthikeyan Mogan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it doesnt work what needs to be done ?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, if it doesn't work then you need to act like a programmer and find out what the problem is.
 
Karthikeyan Mogan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Atlast foound the solution. Use join method in thread to make the child threads execute one after the another and store the result in a vector. Once the child threads complete the execution retrive the resultset from the vector.
but i was able to find this one out as i first tried with a seperate app and then included in my project . Thanks Paul for your advice.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're executing the child threads one after another, what's the point of creating multiple threads?
 
Karthikeyan Mogan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No ! What i did is that make the parent thread wait until the child threads have completed the execution. Say you have some 100 child thread and the main thread need to wait until the child thread completes the execution . The child thread executes concurrently boss so there by efficiency will be improved.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic