你的位置:首页 > ASP.net教程

[ASP.net教程]atitit.taskService任务管理器的设计v1


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

 

任务管理器的点

Sametime_exe_count

Per task sleepMillSec

Timeout_secs

 

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

转载请注明来源: http://www.cnblogs.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;

}

 

}