aspose file tools*
The moose likes Java Micro Edition and the fly likes Multithreading problem - in j2me - webservice connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Multithreading problem - in j2me - webservice connection" Watch "Multithreading problem - in j2me - webservice connection" New topic
Author

Multithreading problem - in j2me - webservice connection

majety srikanth
Greenhorn

Joined: Jan 25, 2011
Posts: 14
I am newbie to j2me.
I am using threading concepts to connect with webservices.
I have two classes - Sync (which acts as main ) and TestConnectionThread(which is used to connect webservice and for checking whether testConnection is succeed)
TestConnectionThread contains post() method which accepts the webservice url and starts the thread(calls run() method)

What I want is - child thread(i.eTestConnectionThread) has to complete first before Sync has to complete. I am not able to use childThread.join() in Sync class because I am using j2me cldc 1.1. So, I tried with, Thread.sleep(), Thread.yield in sync class. but of no use.

Every time, the child Thread is creating successfully and near the ht.call method, it is waiting for some time(because it has to hit webservices and get back the response). So, in this mean while, the control is giving back to the parent( i.e Sync). Once it happend, childThread is not getting the control until the parent (Sync) is over. (Even though I set high priority to childThread or increasing the time in while loop). So, because of that .. even though the testConnection is succeeded, in Sync it is showing isConnection is failed.
Please let me know how can i achieve - Sync has to wait until TestConnectionThread connection is succeded.
(i.e 'TestConnection Thread - GetResult()- got response from webservice:true' has to appear before 'Sync - checkTestConnection() - isConnection value =false' sothat isConnection value will print true)

Here are the programs and console output for tracing

#############################
output
##########################
Sync - checkTestConnection()
current thread name & priority:Thread-4-5
TestConnection Thread - posted parameters - urlhttp://172.16.25.149/fpstcservicebb/stc.asmx
In URL http://172.16.25.149/fpstcservicebb/stc.asmx
Connecting To Server...
TestConnectionThread - run()
TestConnectionThread - run() - thread name and priority :Thread-7-10
TestConnectionThread - run()-inside thread running
TestConnection Thread - GetResult()
soapActionhttp://tempuri.org/TestConnection
In URL http://172.16.25.149/fpstcservicebb/stc.asmx
TestConnection Thread - GetResult() - before ht.call
Connecting To Server....
Connecting To Server.....
Connecting To Server......
Connecting To Server.......
Connecting To Server........
Connecting To Server.........
Connecting To Server..........
Connecting To Server...........
Connecting To Server............
Sync-checkTestConnection()- inside time out
<<<<<<<<<<< thread killed <<<<<<<<<<<<<<<<
Sync-checkTestConnection()-while is over
Sync-checkTestConnection()- inside else block>>>>>>>>>>>>>>>>>>>>>>
Sync - checkTestConnection() - finally value is set to : false
Sync - checkTestConnection() - isConnection value =false
TestConnection Thread - GetResult() - after ht.call
TestConnection Thread - GetResult()- got response from webservice:true

TestConnection Thread - GetResult() - set constants url as http://172.16.25.149/fpstcservicebb/stc.asmx
TestConnection Thread - GetResult() - sending value :false
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multithreading problem - in j2me - webservice connection