Solved

Calling any java method as thread

Posted on 2008-06-16
3
184 Views
Last Modified: 2013-12-29
I have an existing webservices project, with 100+ class files,  each one basically runs a query, and return results.
I need to build some new hits that do several various hits asynchronously.  Then return data.  How can I do this without making a bunch of modifications(or as little as possible) to the various class files.  It needs to be done at this webservice level, I can't have the calling applications do the hits asynchronously.

So my visualized solution is something like:
String a =CallAsThread(ClassLoader.SomeClass.getTheseDBConfigs(),ClassLoader.SomeClass2.getTheseDBConfigs2()));

Where CallAsThread calls the 2 different classes as threads, joins them, gets and returns there results or however this can be accomplished.
0
Comment
Question by:itbeme
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 21798837
Runnable a = new Runnable()
{
   public void run()
   {
       callOne();
    }
};
Runnable b = new Runnable()
{
   public void run()
   {
       callTwo();
    }
};
Thread t1 = a.start();
Thread t2 = b.start();
t1.join();
t2.join();

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21803555
The secret will be in encapsulation here. You say

>>String a =CallAsThread...

Does this mean that you want the result to be in some way a concatenation of strings that are the results of the independent queries?
0
 
LVL 3

Author Closing Comment

by:itbeme
ID: 31467820
To be able to do the way suggested I declared a new thread object passing the Runnable object as a paremeter

          Thread t1 = new Thread (new Runnable() {
            public void run() {
                        results1=doThis1();
                        }
                    }
             );
        Thread t2 = new Thread (new Runnable() {
            public void run() {
                  results2=doThis2();
                        }
                    }
             );
             t1.start();
             t2.start();
          t1.join();
          t2.join();

Thanks
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question