Link to home
Start Free TrialLog in
Avatar of itbeme
itbeme

asked on

Calling any java method as thread

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.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of itbeme
itbeme

ASKER

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