-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use extra scheduler to handle health check.
- Loading branch information
Showing
4 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package fastdfs.client; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.concurrent.*; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
class FastdfsScheduler implements Closeable { | ||
private final ScheduledExecutorService loop; | ||
|
||
FastdfsScheduler(int threads) { | ||
this.loop = Executors.newScheduledThreadPool(threads, new ThreadFactory() { | ||
final String threadPrefix = "fastdfs-scheduler-"; | ||
final AtomicInteger threadNumber = new AtomicInteger(1); | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
return new Thread(null, r, threadPrefix + threadNumber.getAndIncrement()); | ||
} | ||
}); | ||
} | ||
|
||
ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { | ||
return loop.schedule(command, delay, unit); | ||
} | ||
|
||
<V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { | ||
return loop.schedule(callable, delay, unit); | ||
} | ||
|
||
ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { | ||
return loop.scheduleAtFixedRate(command, initialDelay, period, unit); | ||
} | ||
|
||
ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { | ||
return loop.scheduleWithFixedDelay(command, initialDelay, delay, unit); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
try { | ||
loop.shutdown(); | ||
} catch (Exception e) { | ||
// do nothing. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters