How to launch threads from a thread

Hi, I am developing an application to spider web pages and I have basically 3 classes: SpiderController, SpiderPool and Spider.
The idea is that the SpiderController creates SpiderPools each spider pool with some proxy configuration and a list of pages to spider, and finally the Spider is created inside the spider pool and takes one of the pages to spider.
I want to launch each SpiderPool in one thread and then in each SpiderPool I also want to launch one Spider with a page in one thread.
At the moment I have this code:
//Class spider Controller
public class SpiderController{
public executePageSpider{
//list of all the pages to spider
Vector<String> pageList = task.pageList();
//Split the list in two parts one for each spiderpool     
     Vector<String> pageListGroup1 = new Vector<String>(pageList.
               subList(0, pageList.size()/2));
     Vector<String> pageListGroup2 = new Vector<String> (pageList.
               subList((pageList.size()/2)+1,pageList.size()));
     //Creating one spider pool with each part
     //Each spiderpool has a different proxy configuration
     SpiderPool spool1 = new SpiderPool(proxyList.get(0),pageListGroup1);
     SpiderPool spool2 = new SpiderPool(proxyList.get(1),pageListGroup2);
     spool1.run();
     spool2.run();
//Class SpiderPool
public class SpiderPool extends Thread implements Constants{
private Proxy proxy;
private Vector<String> pageList
public void run(){
System.out.println("-------------- Runing Spider pool --------");
for(String page : pageList){                   
Spider sp = new Spider(page);
     sp.run();
//class Spider
public class Spider extends Thread{
public void run(){
//Code to get the page code and wite it into file
The problem that I have is that the spiderpools are not launched as a Thread. The second one (spiderpool2) doesn't start until the first spiderpool finish. By the way the Spiders are in different threads as I can see debugging.
I dont know if I have something wrong in my code...
Anybody can help me about how can I run each SpiderPool in a different thread and from this thread launch the spiders in threads?
Thanks

spool1.run();
spool2.run();      
spool1.start();
spool2.start();

Similar Messages

  • How to remove some thread from my threads

    Hi,
    recently I have send the request to approve my user account in TechNet. They are approve my account and my problem was solved. now the same thread so many users are give their command so each time new command arrived it will shown my unread threads. actually
    I don't want got the unread notification for that particular thread how can remove that from my profile.
    Thanks 
    Ravin Singh D

    Hi,
    There is not currently a way to remove a thread from your thread list, even if you delete your post from the thread.
    The verification threads do eventually get closed out, so it'll only be a matter of time before that thread no longer receives updates.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)
    This just goes to re-emphasize the foolishness of using the reportabug forum (or any forum) to implement the account verification.
    I personally don't use Alerts, so for me the worst part is the fact that these threads completely dominate the reportabug forum, rivaled only by off-topic threads that never seem to be moved promptly.
    David Wilkinson | Visual C++ MVP

  • How to launch photoshop from creative cloud

    i just got the free trail of Photoshop cc. it didn't put a an icon on my desktop (which is fine) but i have no idea how to launch it from the cloud. please help!

    check your programs/programs x86 or applications folder for an adobe > adobe photoshop folder.

  • How to return result from a Thread generically?

    Should be done using some form of callback class like below:
    Is this the right way of doing this or a better way especially trying
    to make it generic. What if I found the value from the Thread and want
    to pass that to some other class and do this generically?
    public interface Command {
       public void execute();
    public class ThreadClass extends Thread {
       private Command command;
       public ThreadClass(Command command) {
          super();
          this.command = command;
       public void run() {
           while (true) {
           if (xyz != null) {
              command.execute();
    }

    Should be done using some form of callback class like
    below:What should?
    Is this the right way of doing this or a better way
    especially trying
    to make it generic. Right way of doing what?
    What if I found the value from the
    Thread and want
    to pass that to some other class and do this
    generically?What value? What do you mean by "pass that to some other class"? What other class? What do you mean by "generically"?
    Can you post a (small but complete) example that actually demonstrates what you are trying to explain?
    public interface Command {
    public void execute();
    public class ThreadClass extends Thread {
    private Command command;
    public ThreadClass(Command command) {
    super();
    this.command = command;
    public void run() {
    while (true) {
    if (xyz != null) {
    command.execute();
    You are putting a thread into an infinite loop and wasting resources.
    So unless you intended on doing that (in which case you probably don't have particularly honourable motives so nobody here will want to help you), then whatever it is you're trying to do with this code, its certainly not the best way of doing it. Assuming its just a typo, then please, in future, test your code before you post it, and cut & paste it into the forums, and use the "Preview" button to check it looks okay.

  • How To Launch Servlet from Desktop App

    Hello Everyone,
    I recently started my programing in JavaEE. First lesson was Servlets.
    My servlet takes the name and a number from a user using a html form and returns a wellcoming message to the user and calculates PI with "number" decimals.
    Well it works using a html form but the next exercise is to launch the servlet from a desktop application. I searched like 2 hours on google and different sites for this. I saw a hint about creating a framework(code was writen in 2001).
    I really really have no idea how to launch the Servlet from a desktop client application.

    The exercise says:
    PI Servlet
    Write a servlet capable of calculating the PI number with a specified number of decimals. Access this servlet:
    1. From a browser, using a HTML form
    2. From a desktop application
    For the calculation of PI use Machin formula PI/4 = 4 arctan(1/5) - arctan(1/239) or a similar one.
    For the calculation of arctan function use Taylor series: arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + (x^9)/9 ...
    My servlet looks like this: without the Methods for calculating PI:
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
             try {
                int len = request.getContentLength();
                byte[] input = new byte[len];
                ServletInputStream sin = request.getInputStream();
                int c, count = 0 ;
                while ((c = sin.read(input, count, input.length-count)) != -1) {
                    count +=c;
                sin.close();
                String inString = new String(input);
                int index = inString.indexOf("=");
                if (index == -1) {
                    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    response.getWriter().print("Eroare la servlet");
                    response.getWriter().close();
                    return;
                String value = inString.substring(index + 1);
                //decode application/x-www-form-urlencoded string
                String decodedString = URLDecoder.decode(value, "UTF-8");
                int decc = Integer.parseInt(decodedString);
                String result = CalculatePI(decc).toString();
                PrintWriter out = response.getWriter();
                try {
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Pi Servlet</title>");
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>Pi Servlet  </h1>");
                out.println("<p> Wellcome <br /> PI cu "+ decodedString + "zecimale este: <p>");
                out.println("<br />" + result);
                out.println("</body>");
                out.println("</html>");
            } finally {
                out.close();
                // set the response code and write the response data
                response.setStatus(HttpServletResponse.SC_OK);
                OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
                writer.write(decodedString);
                writer.write(result);
                writer.flush();
                writer.close();
            catch (IOException e) {
                try{
                    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    response.getWriter().print(e.getMessage());
                    response.getWriter().close();
                catch (IOException ioe) {
        } The Html form :
    <form action="PiServlet" method ="POST">
        Give PI decimals <input type="text" name="PI" size="20"><br />
        <input type="submit" value ="Submit" >
        <input type ="reset" value="Reset" >
    </form>And my desktop application :
    public static void main( String [] args ) throws Exception {
               if (args.length != 1) {
             System.err.println("errrrr");
             System.exit(1);
         String piString = URLEncoder.encode(args[0], "UTF-8");
         URL url = new URL("http://localhost:8084/MySecondServlet/");
         URLConnection connection = url.openConnection();
         connection.setDoOutput(true);
         OutputStreamWriter out = new OutputStreamWriter(
                                  connection.getOutputStream());
         out.write("string=" + piString);
             System.out.println(piString);
         out.close();
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        connection.getInputStream()));
         String decodedString;
         while ((decodedString = in.readLine()) != null) {
             System.out.println(decodedString);
         in.close();
        }Edited by: ELuCID on Jul 22, 2009 9:42 PM
    Edited by: ELuCID on Jul 22, 2009 10:11 PM

  • 2 Threads issues. How to return data from a thread located in other class

    I have 2 questions.
    This is the context. From main I start one thread that does a little job then starts another thread and waits for it to end to continue.
    1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
    synchronized methods outside different classes (and the threads belongs to different classes).
    2) From the main thread I start the Second Thread located in another class like this ClassName obj = new ClassName(arg); obj.start(); obj.join()
    Is that correct for waiting for the created thread to finish ?

    1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
    synchronized methods outside different classes (and the threads belongs to different classes).Threads do not "belong" to classes. Class code executes in a particular thread. The class instances exist as long as something, somewhere, holds a strong reference to them.
    So when you start a new thread, hold a strong reference to the object being executed by that thread. When the thread is done, retrieve your data from that object.
    Even better, don't subclass Thread to create your objects. Instead, implement Callable, and use a ThreadPoolExecutor to execute it.

  • How to remove oneself from discussion thread

    how do you remove yourself from a discussion thread? i asked a question 6 months ago and i still get updates, i have checked my profile and every alert question i have selected no. ***?

    Read here:
    https://discussions.apple.com/static/apple/tutorial/email.html

  • How to append msg from second thread to main GUI thread?

    I am facing a problem which I cannot seem to solve.
    It involves Swing and threads. I have a main GUI running on swing. And it retrieves database information and displays it. On the same GUI I have a JTextArea box which I need another thread to update as and when that second thread recieves message via a multicast socket.
    I managed to create a runnable class of the second thread and successfully ran the second thread with the main thread in tandem. However when I use
    display.append(msgreceived);
    I get a nullPointerException. It works fine when i use System.out.println(msgreceived);.
    What should I have done instead?

    Here are part of the codes for my admin module.
    public class Admin extends JFrame implements ActionListener {
    //declares all the global variables
    private JTextArea display;
    public Admin() {
    super("BX Online - Admin Module");
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    AdminGUI();
    AdminGUI() {
    contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    JPanel newsbox = new JPanel();
    display = new JTextArea(2, 40);
    display.setEditable(false);
    newsbox.add(display);
    contentPane.add(newsbox);
    contentPane.add(tabpaneO);
    setBounds(70, 50, 300, 500);
    pack();
    setVisible(true);
    // all the methods activated by buttons goes here
    static public void main(String[] argv) {
    Admin a = new Admin();
    News b = new News("test");
    The following are part of the codes for my runnable class.
    public class News implements Runnable {
    protected boolean again = true;
    private String name, recieve; //the global variables
    private Thread t;
    public JTextArea display;
    public BXnews(String threadname) {
    name = threadname;
    t = new Thread(this, name);
    System.out.println("New Thread: " + t); //visual check to make sure thread is started.
    t.start();
    private void msg() {
    String recieve = ("testing");
    System.out.println(recieve);
    display.append(recieve);
    public void run() {
    while (again) //creates a loop so thread does not close
    {msg();}
    Well thats abt it. I'm not sure if you can compile this but basically the part I left out was the setup link for the News class which I don't see the need to add as what I primarily intend is for the message testing in News class to appear in Admin class thread in JTextArea "display".

  • How can i get the stack of one thread from another thread

    hi !
    i have a pool threads ,some times all therads in that pool are besy becouse somting lock the threads so there is no free thread to handle ... .
    what i want is a way to get the stack of these thread so i can print them to see way they lock ...
    thanks,
    zvika

    Maybe something like this (haven't actually tried it):
    Add a method to your Threads to print the trace:
    public class MyThread extends Thread {
        public void run() {
        public void printCurrentStack() {
            (new Exception()).printStackTrace(); // or whatever method you choose
    MyThread mt = new MyThread();
    mt.start();
    mt.printCurrentStack();

  • How to catching exceptions from another thread

    hi,guys,i have some code like this:
    public static void main(String[] args) {
    TimeoutThread time = new TimeoutThread(100,new TimeOutException("超时"));
         try{
         t.start();
         }catch(Exception e){
         System.out.println("eeeeeeeeeee");
    TimeoutThread will throws an exception when it runs ,but now i can't get "eeeeeeeeeee" from my console when i runs the main bolck code.so ,somebody help me ,thk.

    hi,ejp,this is my scene:
    getHttpParty(String name) is a method get some information from a web site,this maybe cause many times.now this method is called in my main(String args[]) method.
    i want to terminate getHttpParty if it runs 2s, can you give some simple code to do this.
    thank you very much.
    Edited by: user5449747 on 2010-11-17 上午12:03

  • How to launch executable from a java program

    In c++ we can use a function WinExec to execute exe from a c++ program.
    Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
    Is there a way to do this in Java?
    Vijay

    >>
    class LoadExecutable
    static void loadProcess()
    Runtime r = Runtime.getRuntime();
    Process p = r.exex("winword.exe");
    public static void main(String args[])
    loadProcess();
    }Regards
    - ManikantanBoth of these aren't good ideas - neither of them
    deals with the input or output streams at all.
    Everyone who's posted to this thread should read this.
    None of you knows how to use Runtime.exec properly:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
    aps.html
    MOD
    Thanks for the tips
    -Regards
    Manikantan

  • Shutting down a panel in one thread from another thread.

    For various reasons, I have a program with two threads (actually more than two, but only two are concerned here). One is the main panel that runs at startup, another is a Virtual O'Scope panel with a real-time display. Everything works more or less well, until it's time to exit the program.
    The main program starts by calling a routine to display the VO'scope; this routine calls CmtScheduleThreadPoolFunctionAdv to schedule the VOscope thread with the function VOscopePanelMain.
    VOscopePanelMain initializes things, displays the VOscope panel, and then calls RunUserInterface(); to process events in the VOscope panel.
    When it comes time to close the window, closing the panel (the X box in the upper right corner) triggers the panel callback CB_VoscopePanel, which processes the EVENT_CLOSE: event by calling QuitUserInterface(0); which, in turn, causes RunUserInterface to return to VOscopePanelMain, which then shuts things down, closes the panel properly, and exits. So far so good.
    int CVICALLBACK CB_VoscopePanel (int panel, int event, void *callbackData,
            int eventData1, int eventData2)
        int    iPanelHeight, iPanelWidth, iV2ControlLeft, iV2ControlWidth, iWidth,
            iT2ControlTop, iT2ControlHeight, iHeight, iLeft, iGap, iScreenTop, iScreenLeft,
            iTop, iBoxWidth;
        switch (event) {
            break;
        case EVENT_GOT_FOCUS: //happens when first displayed or refreshed
        case EVENT_PANEL_SIZE: //size the controls on the panel
           ... do stuff here;
            break;
        case EVENT_CLOSE:
            QuitUserInterface(0);  //stop VOscopePanelMain, which in turn closes the panel and cleans stuff up.
            break;
        return 0;
    However, I also want the panel to stop when I close the main program. The only way that I know how to do this cleanly is to have the main program (which has closed all of its panels and is in the process of shutting down) call VOSCOPE_Close_VOScope () which, in turn, calls CallPanelCallback (iHandle_VOscope, EVENT_CLOSE, 0, 0, 0); (which forces a call to CB_VoscopePanel above with the EVENT_CLOSE event), which should call QuitUserInterface, which should cause the RunUserInterface in VOscopePanelMain to return and let it continue to shut down. In addition, after calling CallPanelCallback, the shutdown routine calls CmtWaitForThreadPoolFunctionCompletion to wait for the VOscopePanelMain thread to actually quit and clean up before proceeding.
    But, of course, it doesn't since, and it took me a while to realize this. The call to QuitUserInterface isn't coming from inside of the VOscopePanelMain thread, it's coming from the main panel's thread - which is already in the process of shutting down. So, the main panel thread is telling itself to quit, VOscopePanelMain never gets the QuitUserInterface message, and things stall.
    So: how do I have one thread tell a panel in another thread to cleanly close? Or do I have to get complicated and either replace RunUserInterface in VOscopePanelMain with a loop that processes events manually and looks for a flag, or figure out something with a thread-safe queue? Any help appreciated.
    Attachments:
    Voscope.c ‏76 KB

    Sorry for delay in answering, it took me a while to find time to build up a working example.
    The attached program spawns a thread in a new thread pool and permit you to choose whether to close it from the main thread or the spawned thread itself.
    It appears that in such a minimal configuration the process works as expected. There may be some different configuration in your actual program that prevents this.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?
    Attachments:
    ThreadPoolWithGUI.zip ‏7 KB

  • How to launch Photoshop from Adobe manager

    Photoshop CS6 is shown as installed in Adobe manager, but there is no launch button to open the program.  I click on Photoshop CS6, but nothing happens.

    Check your start menu/ Applications folder liek for any other program.
    Mylenium

  • Dont know how to launch app from creative cloud

    I downloaded premiere pro cc but i cant access the app. i already tried looking for it in the applications folder, not there. tried clicking it on the creative cloud app but not doing anything. only thing i can click on is the 'view tutorials' under it. HELP??? ANYONE???
    #desparate

    Hi There,
    Please find the screenshots to launch Adobe's Applications in the link mentioned below.
    Creative Cloud Help | Launch Creative Cloud apps
    Thanks,
    Atul Saini

  • Can i catch an exception from another thread?

    hi,guys,i have some code like this:
    public static void main(String[] args) {
    TimeoutThread time = new TimeoutThread(100,new TimeOutException("超时"));
    try{
    t.start();
    }catch(Exception e){
    System.out.println("eeeeeeeeeee");
    TimeoutThread will throws an exception when it runs ,but now i can't get "eeeeeeeeeee" from my console when i runs the main bolck code.
    i asked this question in concurrent forums,somebody told me that i can't.so ,i think if i can do this from aspect of jvm.
    thank you for your help
    Edited by: Darryl Burke -- Double post of how to catching exceptions from another thread locking

    user5449747 wrote:
    so ,i think if i can do this from aspect of jvm. What does that mean? You think you'll get a different answer in a different forum?
    You can't catch exceptions from another thread. It's that easy. You could somehow ensure that exceptions from that other thread are always caught and somehow passed to your thread, but that would be a different thing (you would still be catching the exception on the thread it is originating from, as is the only way).
    For example you can use setUncaughtExceptionHandler() on your thread to provide an object that handles an uncaught exceptions (and you could pass that uncaught exception to your other thread in some way).

Maybe you are looking for

  • Using expression

    hi I have to use expression operator in a cube's mapping. i am using two different tables to get a column from each table in input group of the expression. On the bases of these two columns i have to make a decision in CASE statement in output group.

  • IP local pool range not accepted

    I have a client set up with this range: ip local pool ClientVPN 176.16.11.210-176.16.11.241 Somehow it is unable to give an IP to the client... If i change the range: ip local pool VPNproduction 176.16.11.150-176.16.11.160 It works fine... What could

  • Using Flash in porlets

    Hi, I created one portlet and assigned to a remote server. the remote server pointing to jsp which displays the flash movie. i am able to play the flash movie if i access the jsp directly from the web server, but i am not able to see the flash movie

  • JTable custom colouring

    Hi everyone, I've been trying to create a JTable in which the first row and first column have a different background (since they contain "headers" and not actual data). I could not find a way to include headers for both columns and rows, so I defined

  • Brand New TouchSmart 300 internal microphone not working.

    I have been trying to get my internal microphone to work with Skype. I have done all the tests suggested on this forum and everything says that my microphone is working! When I record anything  I get a muffled noise not anything like speech. If I rec