急急急! 线程调用对象报空指针

先上代码。请看下面

 package com.socket.client;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.socket.model.RequestCommand;
import com.socket.server.SocketServer;
import com.socket.service.RequestCommandService;

/** 
 * 启动端口监听入口
 * @author  JQ.Wang   E-mail:wang53400487@hotmail.com 
 * @date 创建时间:2015年8月13日 下午3:46:22 
 * @version 1.0 
 * @parameter  
 * @since  JDK1.7
 * @return  
 */
@Controller
public class RunSocket {

    protected static final Logger log=Logger.getLogger(RunSocket.class);

    private int port = 0;

    @Autowired
    private RequestCommandService requestCommandService;

    public void invoke(){
        new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("=============================im here=====================");

                System.out.println(requestCommandService);

                List<RequestCommand> rcList=requestCommandService.findAllPort(); 
//              log.info("===========================将会启动监听的端口数量为:   "+rcList.size());
//              if (rcList.isEmpty()) {
//                  try {
//                      Thread.sleep(3000);
//                  } catch (InterruptedException e) {
//                      e.printStackTrace();
//                  }
//              }
//              for (RequestCommand requestCommand : rcList) {
//                  //把当前的端口号覆盖port
//                  port=requestCommand.getServer_port();
                    log.info("===========================正在启动的端口是:     "+port);
                    new Thread(new Runnable() {
                        @Override
                        public void run(){
                            log.info("===========================正在启动的端口是:     xxxxxx"+port);
                            new SocketServer().NioServer(8001);
                        }
                    }).start();
//              }
            }
        }).start();
    }
}

由于刚接触线程,线程代码方面的问题,各位朋友也可以指正下。

回归正题,问题出在调用 requestCommandService 时,报了空指针。

  1. =============================im here=====================
  2. Exception in thread "Thread-0" java.lang.NullPointerException
  3. at com.socket.client.RunSocket$1.run(RunSocket.java:44)
  4. at java.lang.Thread.run(Thread.java:745)

可以确认一点的是,这个Service已经注入容器中,因为在Controller类中能正确调用,

请各位大神,帮忙分析下问题所在,万分感谢!

http://bbs.csdn.net/topics/390896429