在Kubernetes执行Hazelcast任务

发布于 2025-02-05 08:56:24 字数 1150 浏览 2 评论 0原文

我有任务“信息掩体”。当我尝试在本地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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白衬杉格子梦 2025-02-12 08:56:24

包含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 .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文