nullpointerexception axis2 webservice

时间:2013-02-13 17:00:21

标签: multithreading web-services nullpointerexception axis2

我在axis2上有一个web服务,在这个类中一个函数启动一个线程,另一个函数检查线程是否仍在运行,但是当我对该函数的请求检查线程仍在运行时,我得到了这个错误:

org.apache.axis2.AxisFault:尝试调用服务方法时发生异常isTaskRunning     at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)     at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)     在org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)     在org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)     在be.kdg.cosys.thesis.ExecutorStub.isTaskRunning(ExecutorStub.java:487)     在be.kdg.cosys.thesis.AllToPublicScheduler.executeTask(AllToPublicScheduler.java:158)     在be.kdg.cosys.thesis.AllToPublicScheduler.incomingApplication(AllToPublicScheduler.java:106)     在be.kdg.cosys.thesis.ParserToScheduler.run(ParserToScheduler.java:111)     在java.lang.Thread.run(未知来源)

这里是网络服务类:

public class Executor {

private Task task = null;
private long startTime = 0;
private long runTime = 0;
private Thread taskThread=null;

public void execute(byte[] object){ 
    ObjectInputStream in = null;
    try {
        in = new ObjectInputStream(new ByteArrayInputStream(object));
        task = (Task) in.readObject();
        in.close();
    } catch (IOException | ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    runTime = task.getRunTime();
    startTime = System.currentTimeMillis();
    taskThread=new Thread(task);
    taskThread.start();
}
public long timeToFinish()
{
    return runTime-(System.currentTimeMillis()-startTime);
}
public boolean isTaskRunning()
{
    return taskThread.isAlive();        
}
public byte[] getTask()
{
    byte[] ser=null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out = null;
    try {
      out = new ObjectOutputStream(bos);   
      out.writeObject(task);
      ser = bos.toByteArray();
      out.close();
      bos.close();
    } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }   
    return ser;
}

}

在webservice的服务器上,我得到一个nullpointerexeception(catalina的日志)

任何人都可以帮助我吗?

约里克

1 个答案:

答案 0 :(得分:0)

是的,您将获得Null指针异常 - 因为不会在启动Thread的Same类实例上调用Web服务方法。由于变量taskThread将为null,并且在方法isTaskRunning()中调用null对象上的方法,因此会导致NullpointerException

理想情况下,如果您需要使用Web服务轮询线程,则应使用一个说明线程状态的威胁性媒体。 intimidatory可以是存储线程状态的数据库表