Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-26-2008, 04:23 PM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
passing a value from parent thread to child thread
Hi All,

I am calling a java program from a unix script .
My oblectives are
1)to pass value from scripts to main java class
2)main class should create a child thread and pass data to child and should return control back to script
3)child thread should run independtly of parent
The calling unix script is part of process and hence should return control back to its calling script immediately.

Findings
1)Without passing data thru setter getter /constructor method to child thread my objectives are met
2)When I pass the data from parent thread to child thread calling unix scripts wait till child thread finishesh its working

call.scr
java Main <list of Arguments>
Main.java
Code:
public class Main { public static void main(String args[]) throws Exception { String data2="Z"; String data1=null; for(int i=0;i<args.length;i++) { data2=data2+","+args[i]; } data1=data2; Child cu=new Child(); cu.setData(data1); data2=null; data1=null; cu.start(); } }
Child.java
Code:
class Child extends Thread { public String data; void setData(String data) { this.data=data; } public void run() { ----------> processing on data } }


I think due to passing of data from parent thread to child thread (Inter thread data communication/Inter process communication)
the threads are not working as desired.

Plz anybody can suggest something.....

Thanx.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-26-2008, 04:44 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
the threads are not working as desired.
To debug your problem you need to add some println() statements to see where the threads are going and what the values are. When you see what is happening, that should help you to change the code so you get the desired results.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-26-2008, 04:52 PM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
Hi Norm,

this is filtered code i have posted,
but when i hv actually deguued it the threads r getting generated succesfully n getting killed in manner of their life cycle.
But the cotrol is not getting back to script till child get killed .
Plz help
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-26-2008, 05:49 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
cotrol is not getting back to script till child get killed .
The jvm will keep control until all the non-daemon threads have ended.
Are you asking how to start a java program from a script and then have the java program return control to the script and still be running? Sounds like an OS interface problem. Can your script start the java program as another process (or whatever) and continue on, leaving the java program running?
Perhaps you could change your design to put all the logic in the java program so there isn't a script/java interface problem.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-27-2008, 09:43 AM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
Quote:
Originally Posted by Norm View Post
The jvm will keep control until all the non-daemon threads have ended.
Hi Norm,

the unwanted results are just because off passing data from parent to child. All other things are working fine.
I am able to call the java prog from the script .But as i desired after parent passes d data and child get Started,control immediately shuld get back to script ,but in case of ppasing data its nt happening
But when I donot pass d data but for testing use hardcoded data in child then all things are getting done as i desired.

Thanx
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-27-2008, 10:38 AM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
Quote:
Originally Posted by sachinj13 View Post
Hi Norm,

the unwanted results are just because off passing data from parent to child. All other things are working fine.

Thanx
Or is it the case that for calling script whole jvm will be a process and not the underlying threads.And hence its behaving in this manner.
But still in case of hardcoded data in child how its working fine is still matter of concern for me.
Thanx
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-27-2008, 04:34 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
whole jvm will be a process
I beleive that is true.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-07-2008, 11:06 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
process boundaries
Quote:
Originally Posted by Norm View Post
I beleive that is true.
In general, should be true. Subject to testing, variables do not cross compilation unit boundaires. To say that something is file scope is to say that you can see it in an editor window, without tabbing to another editor window: That is the definition of a compilation unit.

The JVM is actually the process, as the system sees it. public static void main is a thread within the JVM, which may launch a few threads of it's own - eg console and screen and maybe a monitor to wait on your main. An interesting safety issue is raised here: new Thread().setDaemon; in main and starting it when the jvm was started from a script, is likely to introduce interesting study cases ~ cases that should be studied in rareified stratospherics of thesis subjects and not be done on commercial work.

The jvm likely runs in the process space of the script, carefull attention to code correctness would reveal any intra-thread risks that are not subject to Security Manager issues.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread sims New To Java 4 08-25-2008 03:59 PM
data from the main/GUI thread to another runnin thread... cornercuttin Threads and Synchronization 2 04-24-2008 12:30 AM
If JNI thread call the java object in another thread, it will crash. skaterxu Advanced Java 0 01-28-2008 09:02 AM
Creating a Thread (extending Java Thread Class) JavaForums Java Blogs 0 12-19-2007 11:31 AM
using Thread one198 New To Java 1 11-21-2007 10:01 AM


All times are GMT +3. The time now is 07:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org