gpt4 book ai didi

java - 客户端线程在联系 RMI 服务器时失败 : java. rmi.UnmarshalException:错误解码返回

转载 作者:行者123 更新时间:2023-12-02 11:50:36 29 4
gpt4 key购买 nike

我有一个客户端,它从 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;
}

我已经尝试了不同的虚拟机参数路径,但无法使其工作,非常感谢任何帮助。

最佳答案

Client thread fails when contacting RMI server:

没有。查找 RMI 注册表时失败。查看堆栈跟踪。

java.rmi.UnmarshalException: error unmarshalling return

查看堆栈跟踪。根本错误是

java.lang.ClassNotFoundException: servertest.DictionaryInterface (no security manager: RMI class loader disabled)

您尚未将此类部署到客户端。您似乎同时拥有 servertest.DictionaryInterfaceDictionaryInterface.DictionaryInterface。你不能那样做。两端的包名必须相同。

关于java - 客户端线程在联系 RMI 服务器时失败 : java. rmi.UnmarshalException:错误解码返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47896631/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com