我正在开发一个多线程应用程序,我从JMS收到一些请求,线程正在运行以接收消息。这是我的线程如何工作:
try块中的模型映射器导致了我认为的问题:
patientAdder.addPatient(patientAddMessage, authResult, queueSender, baseUrl, modelMapper);
这里是完整的代码:
Executors.newSingleThreadExecutor().execute(new Runnable() {
public void run() {
while (true) {
SonicQueueMessageSender queueSender = null;
try {
queueSender = new SonicQueueMessageSender(queueConnProvider);
} catch (JMSException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
String patientAddMessage = null;
try {
patientAddMessage = new SonicMessageReceiver(connectionProvider)
.getAddJsonMessage("MirthMessage");
} catch (JMSException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
final AuthModel auth = new AuthModel();
String authResult = null;
final PatientAdder patientAdder = new PatientAdder();
SecurityTokenModel securityToken = null;
String authPostString = null;
try {
authPostString = new ObjectMapper()
.writeValueAsString(auth);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Auth post string is: "+ authPostString);
System.out.println("base url is: " + baseUrl);
String authPostOutput = client
.doGetAuthRestPost(authPostString, url);
try {
securityToken = getAuth(authPostOutput);
} catch (JsonParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JsonMappingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
authResult = securityToken.getAccessToken();
try {
patientAdder.addPatient(patientAddMessage, authResult, queueSender, baseUrl, modelMapper);
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// poster.postMessage(patientAddMessage, authResult);
catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
}
});
我需要将我正在请求的消息映射到bean类,并且我正在创建一个ModelMapper
类对象,该对象具有映射属性的功能,但是当我尝试创建新对象时我的映射器类我得到了一个NPE:
Exception in thread "pool-1-thread-1" java.lang.NullPointerException
at com.prnreferral.util.commons.ModelMapper.mapCanonicalMessageToPatientModel(ModelMapper.java:82)
at com.prnreferral.patientprocess.add.PatientAdder.addPatient(PatientAdder.java:52)
at com.prnreferral.patientprocess.add.PIXSAddPatient$1.run(PIXSAddPatient.java:148)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
我确定该对象是在我通过添加一些条件检查它时创建的,但是有些东西我缺少导致这个问题 我还尝试添加一个新函数来检查此函数是否存在任何问题,但是获取
Exception in thread "pool-1-thread-1" java.lang.NoSuchMethodError: com.prnreferral.util.commons.ModelMapper.printString()V
at com.prnreferral.patientprocess.add.PatientAdder.addPatient(PatientAdder.java:49)
at com.prnreferral.patientprocess.add.PIXSAddPatient$2.run(PIXSAddPatient.java:173)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
我坚持这个问题,不知道该怎么做,任何人都可以帮助我。提前谢谢。