atitit.taskService 任务管理器的设计 v1

本文介绍了一个简单任务管理器的设计与实现过程,利用Java的并发包创建固定线程池来执行任务,通过自定义的任务获取函数来动态生成任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

atitit.taskService 任务管理器的设计 v1

 

任务管理器的点

Sametime_exe_count

Per task sleepMillSec

Timeout_secs

 

作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://blog.youkuaiyun.com/attilax

 

 

 

package com.attilax.task;

 

import java.io.File;

import java.util.concurrent.Callable;

import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;

import java.util.concurrent.FutureTask;

import java.util.function.Function;

 

import org.openqa.jetty.http.SSORealm;

import org.sikuli.script.Screen;

 

import com.attilax.io.filex;

import com.attilax.io.pathx;

 

public class TaskService {

public  ExecutorService fixedThreadPool;

private int threadCount;

private Callable task;

private int pertask_sleeptime_millsecs;

private Function task_getter;

public static void main(String[] args) {

new filex().In_the_pc_machine_directory("c:\\0011windows")

.written_to_the_file().comma()

.the_content_is("om_mani_padme_hum").the_file_name_is_random()

.the_extension_is("txt").exe_single();

System.out.println("--f");

Callable task_my = new Callable() {

 

@Override

public Object call() {

new filex().In_the_pc_machine_directory("c:\\0011windows")

.written_to_the_file().comma()

.the_content_is("om_mani_padme_hum").the_file_name_is_random()

.the_extension_is("txt").exe_single();

  return null;

 

}

};

Function task_getter=new Function<Object,Callable>() {

 

@Override

public Callable apply(Object t) {

return task_my;

}

};

new TaskService().setTask(task_my).TasksCount(10).at_the_same_time().and_pertask_sleeptime_millsecs_is(100).exe();

}

 

private TaskService setTask(Callable task_my) {

//this.task_getter=task_my;

this.task=task_my;

return this;

}

 

private void exe() {

fixedThreadPool = Executors.newFixedThreadPool(this.threadCount);

//Callable apply = (Callable) this.task_getter.apply(null);

//FutureTask<Object> task = new FutureTask<Object>(apply);

for (double i = 5; i >0; ) {

try {

FutureTask<Object> task = new FutureTask<Object>(this.task);

fixedThreadPool.execute(task);

 

Thread.sleep(this.pertask_sleeptime_millsecs);

//i++

catch (Exception e) {

e.printStackTrace();

}

}

}

 

private TaskService and_pertask_sleeptime_millsecs_is(int i) {

this.pertask_sleeptime_millsecs=i;

return this;

}

 

private TaskService at_the_same_time() {

// TODO Auto-generated method stub

return this;

}

 

private TaskService TasksCount(int i) {

this.threadCount=i;

return this;

}

 

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值