This commit is contained in:
Redkale
2017-03-30 23:19:54 +08:00
parent a7dd22569c
commit a57574dd10
2 changed files with 34 additions and 2 deletions

View File

@@ -25,8 +25,8 @@ public class WorkThread extends Thread {
this.setDaemon(true);
}
public void submit(Runnable runner) {
executor.submit(runner);
public Future<?> submit(Runnable runner) {
return executor.submit(runner);
}
public ExecutorService getExecutor() {

View File

@@ -0,0 +1,32 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.service;
import java.util.concurrent.*;
import org.redkale.net.WorkThread;
/**
*
* @author zhangjx
*/
public abstract class AbstractService implements Service {
protected Future<?> submit(Runnable runner) {
Thread thread = Thread.currentThread();
if (thread instanceof WorkThread) {
return ((WorkThread) thread).submit(runner);
}
return ForkJoinPool.commonPool().submit(runner);
}
protected ExecutorService getExecutor() {
Thread thread = Thread.currentThread();
if (thread instanceof WorkThread) {
return ((WorkThread) thread).getExecutor();
}
return ForkJoinPool.commonPool();
}
}