由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 求思路
相关主题
问各位大牛一个java time scheduler问题Another ?: Re: Keep track # of threads
请教一个Jscript和restful的问题请问关于用threadPoolExecutor实现threadpool的问题?
Re: salesforce用的什么数据库产品呀?问个多线程的问题
一个关于GWT的问题问一个基础问题
请教一下spring batch adminthread signaling 的一个问题
除了core spring,还有spring的啥sub project应该会呢Java NIO 问题求教
AOP这东西听起来很不错JDK 1.5 is out
做一些贡献:threadPool请教jconsole问题
相关话题的讨论汇总
话题: spring话题: threadpool话题: 运行话题: status话题: task
进入Java版参与讨论
1 (共1页)
o***i
发帖数: 603
1
抱歉不知道怎么取个好subject
问题是这样的,服务器端需要运行一个单线程,客户端需要查看这个线程的状态(运行
否),并且需要可以控制那个线程如启动/暂停/停止
大牛们给提供个思路?
p*****2
发帖数: 21240
2
启一个service控制线程?貌似就可以了吧。
F*******X
发帖数: 143
3
"GoodSubjectService" 这名字怎样?够清楚直接。
o***i
发帖数: 603
4
这个web application的多线程和一般程序的不太一样吧,具体怎么个不一样有没有什么
总结的?
另外,在spring下,有什么好的解决方案么?TaskExecutor?

【在 p*****2 的大作中提到】
: 启一个service控制线程?貌似就可以了吧。
g*****g
发帖数: 34805
5
You don't check the status of a thread, you check the status of a task.
Usually you'd use a threadpool, but you can use a simple timer task too. The
simplest way to do it may be like this, with Spring for example. @Scheduled
will use a default threadpool btw.
class MyService {
String status;

@RequestMapping(yourURL)
public getStatus(){return status;}
@Scheduled(yourSchedule)
public runTask {
//change status as you need.
}
}
o***i
发帖数: 603
6
我当前的实现就是这样的,每天早上运行一次,能查看status
问题是我现在想扩展一下功能:
1.能改runTask的schedule
2.能随时启动这个runTask(如果不在运行的话)
3.如果在运行,能暂停/继续/停止
4.保证只有一个runTask在运行

The
Scheduled

【在 g*****g 的大作中提到】
: You don't check the status of a thread, you check the status of a task.
: Usually you'd use a threadpool, but you can use a simple timer task too. The
: simplest way to do it may be like this, with Spring for example. @Scheduled
: will use a default threadpool btw.
: class MyService {
: String status;
:
: @RequestMapping(yourURL)
: public getStatus(){return status;}
: @Scheduled(yourSchedule)

o***i
发帖数: 603
7
这个runTask需要运行一系列subTasks,这些个subTasks需要顺序执行,但是如果中断的
话不需要回滚
启动/停止都难,这个暂停/继续还没有好的思路。
Spring batch能用在这里么?
我看Spring batch有个spring batch admin,不过好久没有更新了

【在 o***i 的大作中提到】
: 我当前的实现就是这样的,每天早上运行一次,能查看status
: 问题是我现在想扩展一下功能:
: 1.能改runTask的schedule
: 2.能随时启动这个runTask(如果不在运行的话)
: 3.如果在运行,能暂停/继续/停止
: 4.保证只有一个runTask在运行
:
: The
: Scheduled

k********e
发帖数: 368
8
用原始的unix shell也可以
p*****2
发帖数: 21240
9

什么
有大牛说说为什么不一样吗?web app不能用core java的东西吗?

【在 o***i 的大作中提到】
: 这个web application的多线程和一般程序的不太一样吧,具体怎么个不一样有没有什么
: 总结的?
: 另外,在spring下,有什么好的解决方案么?TaskExecutor?

g*****g
发帖数: 34805
10

If you want to change it after restart, make it a property, if you want to
change
while running, make it read a field and you expose another web interface to
change the field.
Add a startNow interface.
Similar to above, whether a task can be cancelled or not depends on what it
does and your implementation, you can google on that.
If you have one instance, do a synchronized, if you have a cluster, lock on
DB/zookeeper etc.

【在 o***i 的大作中提到】
: 我当前的实现就是这样的,每天早上运行一次,能查看status
: 问题是我现在想扩展一下功能:
: 1.能改runTask的schedule
: 2.能随时启动这个runTask(如果不在运行的话)
: 3.如果在运行,能暂停/继续/停止
: 4.保证只有一个runTask在运行
:
: The
: Scheduled

相关主题
除了core spring,还有spring的啥sub project应该会呢Another ?: Re: Keep track # of threads
AOP这东西听起来很不错请问关于用threadPoolExecutor实现threadpool的问题?
做一些贡献:threadPool问个多线程的问题
进入Java版参与讨论
b***i
发帖数: 3043
11
你这个任务多长时间?我看google app engine非常胜任。

【在 o***i 的大作中提到】
: 我当前的实现就是这样的,每天早上运行一次,能查看status
: 问题是我现在想扩展一下功能:
: 1.能改runTask的schedule
: 2.能随时启动这个runTask(如果不在运行的话)
: 3.如果在运行,能暂停/继续/停止
: 4.保证只有一个runTask在运行
:
: The
: Scheduled

a****i
发帖数: 1182
12
我感觉这是一个非常明显的JMX
如果要自动检查、运行,上quartz

【在 o***i 的大作中提到】
: 抱歉不知道怎么取个好subject
: 问题是这样的,服务器端需要运行一个单线程,客户端需要查看这个线程的状态(运行
: 否),并且需要可以控制那个线程如启动/暂停/停止
: 大牛们给提供个思路?

t*******e
发帖数: 684
13
cpu intensive用Spring JMX。data intensive用springbatch。
o***i
发帖数: 603
14
可以用,但是有很多不一样的地方吧
看这个帖子:
http://stackoverflow.com/questions/533783/why-spawning-threads-
ntainer-is-discouraged/533847#533847
这个只是冰山一角吧

【在 p*****2 的大作中提到】
:
: 什么
: 有大牛说说为什么不一样吗?web app不能用core java的东西吗?

o***i
发帖数: 603
15
恩,别的都还简单的,3 实现起来太麻烦了,我再找有没有现成的框架可以用的,spri
ng batch似乎不太合适我的情况

to
it
on

【在 g*****g 的大作中提到】
:
: If you want to change it after restart, make it a property, if you want to
: change
: while running, make it read a field and you expose another web interface to
: change the field.
: Add a startNow interface.
: Similar to above, whether a task can be cancelled or not depends on what it
: does and your implementation, you can google on that.
: If you have one instance, do a synchronized, if you have a cluster, lock on
: DB/zookeeper etc.

o***i
发帖数: 603
16
嗯,多谢建议,我研究一下JMX
现在spring已经有些简单的sheduling功能了(复杂的还是需要配合quartz的),应该够
用,我不想再引入quartz

【在 a****i 的大作中提到】
: 我感觉这是一个非常明显的JMX
: 如果要自动检查、运行,上quartz

o***i
发帖数: 603
17
googled one more:
Forbidden technique: Multi-threading inside J2EE server
http://codinglogs.blogspot.com/2010/04/forbidden-technique-mult

【在 o***i 的大作中提到】
: 可以用,但是有很多不一样的地方吧
: 看这个帖子:
: http://stackoverflow.com/questions/533783/why-spawning-threads-
: ntainer-is-discouraged/533847#533847
: 这个只是冰山一角吧

g*****g
发帖数: 34805
18
3也没啥难得。如果你的一个task时间比较长,有loop的话,设个flag,每次循环查一
下就得了。

spri

【在 o***i 的大作中提到】
: 恩,别的都还简单的,3 实现起来太麻烦了,我再找有没有现成的框架可以用的,spri
: ng batch似乎不太合适我的情况
:
: to
: it
: on

g*****g
发帖数: 34805
19
This is wrong. container manages its own threadpool. But it doesn't prevent
you from using your own threadpool for other tasks.
Spring scheduler, for example, runs in its own threadpool.

【在 o***i 的大作中提到】
: googled one more:
: Forbidden technique: Multi-threading inside J2EE server
: http://codinglogs.blogspot.com/2010/04/forbidden-technique-mult

f**r
发帖数: 865
20
hrmm, 我乱说几句,外行了别笑话。:-)
我觉得服务器端可以用REST API, 刚才看了一眼javax.rs.ws.core, 好象很多
boiler plate code 都已经写好了,只需要写如何处理各种命令就行了。在
客户端查询也很方便,在命令行用curl 就行, 用browser也可以。
命令/结果的格式的话JSON的格式很自由,又有现成的serializer和
deserializer,而且是human readable。
在服务器端我觉得 java.util.concurrent.ScheduledExecutorService看上
去挺好用的。 这个东东可以给你返回一个ScheduledFuture, 相当于一个
handle, 可以用来查结果,查状态,取消,取消了以后用
ScheduledExecutorService又可以重新schedule, 或者立即运行.
同一台机器上只让一个thread运行某个task应该不难。想要实现pause的
话,我觉得可以在stop/pause的时候取消task, 但是之前要设定好下次运行
的resume point; 比如pause()的时候,下次运行就从currentSubTask
开始,stop()的时候,下次运行就要从firstSubTask开始。
c*********e
发帖数: 16335
21
本人粗浅,说错了别笑话阿。
可不可以在class里设一个static int theStatus,初始值为0,线程运行之后,把这个
int值设置为1,结束的时候再设为0.通过查询这个int的值,就可以知道线程状态。通
过servlet可以传值。
很多时
候,用这个方法比用session简单。
至于控制那个线程如启动/暂停/停止,可以用if (theStatus == 1)来做些小coding.

【在 o***i 的大作中提到】
: 抱歉不知道怎么取个好subject
: 问题是这样的,服务器端需要运行一个单线程,客户端需要查看这个线程的状态(运行
: 否),并且需要可以控制那个线程如启动/暂停/停止
: 大牛们给提供个思路?

o***i
发帖数: 603
22
嗯。暂且用了spring的TaskScheduler。

prevent

【在 g*****g 的大作中提到】
: This is wrong. container manages its own threadpool. But it doesn't prevent
: you from using your own threadpool for other tasks.
: Spring scheduler, for example, runs in its own threadpool.

1 (共1页)
进入Java版参与讨论
相关主题
请教jconsole问题请教一下spring batch admin
怎么能学成J2EE的全能除了core spring,还有spring的啥sub project应该会呢
请教一下用过JMX (Java Management Extension)的朋友AOP这东西听起来很不错
问个deploy相关的问题做一些贡献:threadPool
问各位大牛一个java time scheduler问题Another ?: Re: Keep track # of threads
请教一个Jscript和restful的问题请问关于用threadPoolExecutor实现threadpool的问题?
Re: salesforce用的什么数据库产品呀?问个多线程的问题
一个关于GWT的问题问一个基础问题
相关话题的讨论汇总
话题: spring话题: threadpool话题: 运行话题: status话题: task