开发者

Question on a tutorial

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 Quest开发者_运维百科ion: 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() { //...}
  }
}


You can put the code into Eclipse, run 'Refactor: convert member type to toplevel' and then examine the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜