我有一个客户端从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参数路径,但无法使其工作,非常感谢任何帮助。
答案 0 :(得分:1)
联系RMI服务器时客户端线程失败:
没有。查找RMI注册表时失败。查看堆栈跟踪。
java.rmi.UnmarshalException: error unmarshalling return
查看堆栈跟踪。潜在的错误是
java.lang.ClassNotFoundException: servertest.DictionaryInterface (no security manager: RMI class loader disabled)
您尚未将此类部署到客户端。您似乎同时拥有servertest.DictionaryInterface
和DictionaryInterface.DictionaryInterface
。你不能这样做。包裹名称必须在两端相同。