在Kubernetes执行Hazelcast任务
我有任务“信息掩体”。当我尝试在本地Hazelcast运行它时,它可以正常运行,
public static void main(String[] args) throws Exception {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IExecutorService executor = hazelcastInstance.getExecutorService("exec");
for (int k = 1; k <= 1000; k++) {
Thread.sleep(1000);
System.out.println("Producing echo task: " + k);
Future<InfoHz> a = executor.submit(new InfoTask("a", "b", "c"));
a.get();
}
System.out.println("EchoTaskMain finished!");
}
但是当我尝试在Kubernetes中使用Kubernetes的Hazelcast执行此操作时,我得到了HazelcastSerializationException
我应该如何解决此问题?
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: my.hazelcast.InfoTask
update
为什么Hazelcast中没有提及 doc 关于任务序列化?它如何工作并且不抛出HazelcastSerializationException
当他们不在classPath中添加jar时?
I have task 'InfoTask' . When I tried to run it in local hazelcast it works
public static void main(String[] args) throws Exception {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IExecutorService executor = hazelcastInstance.getExecutorService("exec");
for (int k = 1; k <= 1000; k++) {
Thread.sleep(1000);
System.out.println("Producing echo task: " + k);
Future<InfoHz> a = executor.submit(new InfoTask("a", "b", "c"));
a.get();
}
System.out.println("EchoTaskMain finished!");
}
but when I tried to execute this in kubernetes with hazelcast in kubernetes I got HazelcastSerializationException
How should I fix this ?
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: my.hazelcast.InfoTask
UPDATE
why there is no mention in hazelcast doc about serialization of task ? How it can work and dont throw HazelcastSerializationException
when they dont add jar in classpath ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
包含
my.hazelcast.infotask
的代码需要在Hazelcast Pod的类中。有多种方法可以实现这一目标,具体取决于您选择在Kubernetes上部署的方式。
两种方式,但还有其他:
简单的类路径:
如果您使用 helm 然后
folumememounts 允许您制作包含可用代码的目录。从 docker:extergeend----- new-jars-or-files classpath 使该概念正常工作。
自定义jar:使用
with-with intedencies
构建自己的图像,然后它只是POD,配置和代码的单个图像,而不是外部。 这里是一个例子。The code that contains
my.hazelcast.InfoTask
needs to be on the classpath of the Hazelcast pod.There are a number of ways to achieve this, depending on how you choose to deploy on Kubernetes.
Two ways, but there are others:
Simple classpath :
If you use something like helm then the
volumeMounts
allows you to make a directory containing your code available. It's easier here to start with Docker : extending-classpath-with-new-jars-or-files to get the concept working.Custom Jar : build your own image, using
jar-with-dependencies
, then it's just a single image for the pod, configuration and code can be baked in rather than external. Here's an example .