Solved

Calling any java method as thread

Posted on 2008-06-16
3
167 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strDist challenge 35 84
mapShare challenge 13 68
solarwind tftp server 2 30
Cipher Configuration on Apache HTTPD 4 16
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now