• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get result from java when java thread is running in background

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will call java program by shell script.
This java start the thread and return the result to the shell script.
My problem is shell script is waiting upto stop the thread.
I want the result when thread is running in background.
please reply.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"result" and "running" are two mutually exclusive terms. The whole definition of "result" is what you get after it finishes running.

If you're actually looking for the success/failure of the attempt to launch a thread, that's different. However a Java thread runs in a JVM, and the JVM process itself doesn't complete until all of its internal threads (which may not correspond to OS threads) have terminated.

Which is all I can say without knowing more.
 
rama ilango
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for example
this is my script file as shelltest.sh

output=`java test`
echo "$output";
echo "success";

when run this script, it run the test.java.
this java file call the thread.
So this script is completed, after stop the thread only.
But i want : when thread is running in background, the script file should print the success(It is in echo) and come out from sh.
reply me
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand correctly, you want to start a java process and return. If that's what you want:

java test &
echo Success

and that's it. & is a special bash character that tells it to invoke the command in a background process.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic