我有一个客户端,它从JSP页面获取输入,然后将其提供给线程,线程被添加到线程池中,当它执行线程时,会联系RMI服务器以获取远程对象,然后应返回将显示在新JSP页面上的结果,问题是一旦执行可运行代码,我会得到以下错误:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: servertest.DictionaryInterface (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at Client.LookupWorker.run(LookupWorker.java:27)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: servertest.DictionaryInterface (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)Thread didnt finish its job properly, error: java.lang.NullPointerException
下面是JSP页面背后的Java代码
if (request.getParameter("word") != null) {
String word = request.getParameter("word");
String res;
System.out.println("The word to find: "+word);
// Get handle on our pool
WorkerPool pool = WorkerPool.getInstance( );
// Create Job
LookupWorker wordWork = new LookupWorker(word);
// Add job to pool
res = pool.addJob(wordWork);
request.getSession().setAttribute("result", res);
response.sendRedirect("/SearchResults");
}
以下是线程类:
package Client;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import DictionaryInterface.DictionaryInterface;
public class LookupWorker implements WorkerPlan {
private String word;
private String jobName;
private String serverResult;
private long threadId;
public LookupWorker(String w) {
super();
this.word = w;
jobName = "Lookup Job";
}
@Override
public void run(){
DictionaryInterface Dictonary = null;
try {
Dictonary = (DictionaryInterface) Naming.lookup("rmi://127.0.0.1:1099/DictionaryService");
} catch (MalformedURLException | RemoteException | NotBoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
serverResult = Dictonary.lookup(word);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(serverResult);
threadId = Thread.currentThread().getId();
}
public String getServerResult() {
return serverResult;
}
public String getWord() {
return word;
}
public String getJobName() {
return jobName;
}
@Override
public String toString() {
return jobName + " [Id= " + threadId + "word= " + word + ", serverResult= " + serverResult + "]";
}
}
执行线程时涉及的池代码:
public String addJob(WorkerPlan job) {
String result;
threadCounter++;
// Adding new lookup job to our queue
System.out.println("Adding a " + job.getJobName() + " to the queue. Searching for: " + job.getWord() + " Job number: " + threadCounter);
executor.execute(job);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // sleep so we can wait for rmi object to come in
System.out.println(job.toString());
result = job.getServerResult();
return result;
}
我为VM参数尝试了不同的方法,但无法实现,非常感谢您的帮助。