Question on a tutorial

Posted by hansa on Stack Overflow See other posts from Stack Overflow or by hansa
Published on 2010-02-23T12:10:01Z Indexed on 2010/05/21 12:00 UTC
Read the original article Hit count: 217

Filed under:
|

Hello,

i´m trying to get following tutorial to run and understand:

http://www.ibm.com/developerworks/web/library/wa-cometjava/index.html

In the example code which can be downloaded at the bottom of the page is everything in one class with two inner classes.

How can i make the the thread of "MessageSender" (Listing 3) visible to "The Weatherman" (Listing 4) so i can use it in the run method without using inner classes?

Thank you hansa

Reformulation of Question: How to make the send-method of inner class MessageSender make accessible in ClassThatDoSomething.

Example-Code:

public class Example extends HttpServlet implements CometProcessor {

  private MessageSender messageSender = null;

  @Override
  public void init() throws ServletException 
  {
  // starts thread MessageSender
  }

  public event(CometEvent)
  {
    // Object of ClassThatDoSomething gets created started
  }


  private class ClassThatDoSomething {


    public void start() 
    {  
      Runnable runnable = new Runnable() {

      public void run(){
          messageSender.send(message);
      }
      Thread thread = new Thread(runnable);
      thread.start();
  }
    }

  private class MessageSender implements Runnable {

    public void send(String message) { //... }

    public void run() { //...}
  }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about threads