Coder Social home page Coder Social logo

stopInstance Asyn task about powerjob HOT 9 CLOSED

powerjob avatar powerjob commented on May 17, 2024
stopInstance Asyn task

from powerjob.

Comments (9)

KFCFans avatar KFCFans commented on May 17, 2024

你好,我测试了一下,stop的功能是没问题的,见下图:
image

首先,Stop不是一个保证可靠的方法,如果发现任务仍在 running,可以再次 Stop。
其次,Stop 任务的前提条件是该任务能被 stop,也就是需要有能被打断的点,比如 Thread.sleep,如果线程一直占用 CPU 执行,Java并没有提供 API 来终止该线程。
最后,如果还有问题的,欢迎继续反馈。顺便带上你的操作系统信息、Java版本、PowerJob版本等信息。

from powerjob.

slyang520 avatar slyang520 commented on May 17, 2024

类似与SchedulerX2 的
public void kill(JobContext context)
https://help.aliyun.com/document_detail/148193.html
因为停止是否成功和业务有关。

from powerjob.

KFCFans avatar KFCFans commented on May 17, 2024

也就是增加一个回调接口,让你自己处理 kill 逻辑吧。
说实话框架设计阶段我考虑过这个方案,但是先不到具体的业务应用场景,能麻烦你举个例子吗?
如果有合适的业务场景,我会在下个版本支持的。

from powerjob.

slyang520 avatar slyang520 commented on May 17, 2024

也就是增加一个回调接口,让你自己处理 kill 逻辑吧。
说实话框架设计阶段我考虑过这个方案,但是先不到具体的业务应用场景,能麻烦你举个例子吗?
如果有合适的业务场景,我会在下个版本支持的。

1L 那个就是很常见的场景。

from powerjob.

KFCFans avatar KFCFans commented on May 17, 2024

不好意思,我其实没太看懂 1L 那个例子的意思 😂
代码在同步执行的时候,我提供给你调用 kill 接口的方法也无济于事啊......

其实我想问的是:
什么情况下需要主动结束任务,我认为的 stopInstance 是用在机器过载情况下手动停止某些任务实例的方法,所以只是一个单纯打断的操作。在我这种理解下,stopInstance 的实现也就是简单的打断线程。
而根据你的描述,似乎是把 stopInstance 作为了一个比较常规的业务操作,我很想知道是什么样的场景下需要使用 stopInstance。

from powerjob.

slyang520 avatar slyang520 commented on May 17, 2024

image

阿里云的kill示例 嘻嘻

from powerjob.

KFCFans avatar KFCFans commented on May 17, 2024

所以说,这个示例只是为了演示而演示的。
如果 kill 的意义是让任务停止,我直接 stop 线程不是一样能到达效果吗?
我需要的是真实有意义的且目前我这种 stop 机制无法支持的业务场景。
如果没有,那其实就是没有必要的需求。

from powerjob.

KFCFans avatar KFCFans commented on May 17, 2024

这个例子的 stop 判断完全可以换成 Thread.interrupted(),我的 stop 一样能达到目的。

from powerjob.

w-sf avatar w-sf commented on May 17, 2024

@KFCFans 我遇到个实际情况,就是监听socket端口接收数据,点运行后确实监听了,但是无法终止,并且jvm配置了-Dpowerjob.worker.allowed-force-stop-thread=true

from powerjob.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.