wood burning stoves 2.0*
The moose likes Web Services and the fly likes Calling a web service in a Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Calling a web service in a Thread " Watch "Calling a web service in a Thread " New topic
Author

Calling a web service in a Thread

TirupathiRao Pattapuraju
Greenhorn

Joined: Dec 09, 2010
Posts: 7
Hi,

I have a class with vector.i have a web service which can only fetch 20 records at a time provided the start point and endpoint from a storage of 100 records. so i want to call a thread for 5 times as (sp=0,ep=20)(sp=21,ep=40)... like so and want to fill those values in the vector how can i achieve the same.

Thanks and regards

tirupathi rao.P
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
What do you have that works now in a single request?

Bill
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Hi TirupathiRao,
I don't think that's a good design practice. You'll end up writing extra code to deal with threading mechanism, assembling response and fault handling. What issues do you have in getting all the 100 records in one go?Unless you show all the records in a web page or to process at a time, you can look up for smaller chunks like 20 at a time.


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
TirupathiRao Pattapuraju
Greenhorn

Joined: Dec 09, 2010
Posts: 7
Naren Chivukula wrote:Hi TirupathiRao,
I don't think that's a good design practice. You'll end up writing extra code to deal with threading mechanism, assembling response and fault handling. What issues do you have in getting all the 100 records in one go?Unless you show all the records in a web page or to process at a time, you can look up for smaller chunks like 20 at a time.


First Of All thank you Naren ...

Here is the abstract of the limitaion i am facing..Actullay i am consuming the web service provided by the Siebel CRMOD to fetch the Accounts(Thousands of Records) lying there in their server.The limiations is a call can give 100 records at time only so i will loop thru the logic to fetch 100 by 100 by providing start point as 0,100,200.... and add them to a list for later use and will do this loop until the response contain records<100.

Say if there are 5000 records i have to loop for 50 times which is a time consuming process.so i am checking that can i take threads help to achieve this.Can you guide on the same.

Thanks and regards
Tirupathi Rao.P
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Hi TirupathiRao,

Welcome to JavaRanch.

What Naren has stated is that explicit control on the thread part you should have to take care if you attempt to employ threads. Yes of course that may be an overhead. But considering the advantage and its demand, you can bear the cost of it!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Hi TirupathiRao,
Thread are usually applied to perform parallel activities of slightly different in behaviour. For example, on a browser user can scroll and at the same time load an applet or call two different web services at the same time and consolidate their responses. If you are planning to use threads for this particular purpose, you'll end up waiting for other threads to complete and join all the threads and eventually construct different thread out comes into a single response. Did you check if you could do all the records in one go? I suspect you would get memory related problems and more likely if your design/coding is not well done.
TirupathiRao Pattapuraju
Greenhorn

Joined: Dec 09, 2010
Posts: 7
Naren Chivukula wrote:Hi TirupathiRao,
Thread are usually applied to perform parallel activities of slightly different in behaviour. For example, on a browser user can scroll and at the same time load an applet or call two different web services at the same time and consolidate their responses. If you are planning to use threads for this particular purpose, you'll end up waiting for other threads to complete and join all the threads and eventually construct different thread out comes into a single response. Did you check if you could do all the records in one go? I suspect you would get memory related problems and more likely if your design/coding is not well done.


Actullay i have to live with the limiataion posed by the Siebel CRMOD(fetch 100 at time).So i want to reduce the time its is taking to fetch the whole records.that is why i am planning to go with threads.
I want to implement the following logic

class have a boolean like isAnyRecLeft=true; and a vector accList.

create 10 threads at one shot and wait.

if any thread fetches records less than <100

exit the process. if not so create 10 more threads.

like this can i adopt this process .if so can you guide me to deploy this plan.


thanks and regrds
Tirupathi Rao.P
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Okay, if you really want to go with that approach knowing downs, it's up to you. I'd rather call sequentially in a for loop as it would not make any difference because you are calling the same web service.

So, what problems are you facing in implementing that? Isn't that straightforward to implement? All you have to do is to create threads and invoke web service.
TirupathiRao Pattapuraju
Greenhorn

Joined: Dec 09, 2010
Posts: 7
Naren Chivukula wrote:Okay, if you really want to go with that approach knowing downs, it's up to you. I'd rather call sequentially in a for loop as it would not make any difference because you are calling the same web service.

So, what problems are you facing in implementing that? Isn't that straightforward to implement? All you have to do is to create threads and invoke web service.



Thank you very much Naren..As you suggested i will stick to my legacy sequential for loop.

But i just want to give a try with threads to check whether it will be any value addition in terms of over all process time.


Thanks and Regards
Tirupathi Rao.P
merry jonson
Greenhorn

Joined: Jun 11, 2014
Posts: 1
Thank you for the information. It helped me best way. Thanks....
 
 
subject: Calling a web service in a Thread