Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling any java method as thread

Posted on 2008-06-16
3
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

636 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