?
Solved

Calling any java method as thread

Posted on 2008-06-16
3
Medium Priority
?
206 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 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