本就不能wwW282secom.dll登入了,还可以继续282se收视的

无论什么网线目前986se都是,无法在wwW986seCom收视里面的节目啦_百度知道
无论什么网线目前986se都是,无法在wwW986seCom收视里面的节目啦
我有更好的答案
在局域网中常见的网线主要有双绞线、同轴电缆网线&编辑要连接局域网,网线是必不可少的。它是用来和RJ45水晶头相连的。它的特点就是价格便宜,所以被广泛应用,如我们常见的电话线等、光缆三种。&双绞线,是由许多对线组成的数据传输线
你讲的太啰嗦了
没你讲的那么复杂
我刚查到的【ffX.3sax.biz】还能将就用
采纳率:93%
来自团队:
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。通过这个版块,关注了解我们的最新消息
遇见最好的售后管理系统!&&
广告招租 webmaster#163dz.com
只需一步,快速开始
查看: 2447|回复: 8
威望3898 在线时间624 小时金币1978968 贡献660 存款0 最后登录注册时间帖子精华0积分4558阅读权限100UID42638
TA的每日心情奋斗 16:23:09签到天数: 9 天[LV.3]偶尔看看II金币1978968 贡献660 存款0 威望3898 最后登录帖子积分4558注册时间UID42638
一台康佳P29SE282彩电,开机,里面有间断的吱声,指示灯一闪一灭,
测量主电压随叫声在50---100V多跳动,带假负载100W灯泡故障依旧,
以为是电源损坏,检修无结果,随后用万能模块代换,灯泡常亮不闪
,接行负载后,故障又出现,电源指示灯一闪一灭,怀疑行负载短路
,+B处串100W灯泡开机,电源指示灯不再闪,但是灯泡很亮,和接在
+B滤波处一样亮,证明行有短路,拆掉彩行,粗测量其他行组件无
短路,换彩行,出现光栅,雪花点,接入信号,出现怪病,一但有图象
场幅度立刻变的1/3那么窄,AV也一样,进总线调整,菜单一次,然后
迅速5次呼号,显示FAC 60H,此时候调整幅度以及行中心等是无效的,
要按节目“0”,切换到FAC 50H 扫描模式,调整幅度恢复正常,按
呼号一次显示FAC OFF 推出总线,并保存。此机修复!
1 以为是电源故障
& && &2 进总线就调整,结果是调的60HZ模式所以图象无改变
& & 3 用读写器写数据无效,出现梯形失真
总结:1此机含有ROM母块校正,所以用空白另写程序无效,
即使复制原机的,按上后依然出怪毛病,必须是
&&有母块校正程序的才可以,这点和长红部分机器
& & 很相似!
& &2此机器的电源不能用加负载,否则误判(有时间
的朋友可以试验一下用小的假负载能不能工作)
一波三折,一头雾水,终于修好这破机器,回想一下,就是技术
技术不差呀!!!j
还是枝术高。机子己修复。
好经验,给你加分了
原创内容,论坛有您更精彩!
精品文章,论坛有您更精彩!
总评分:&威望 + 35&
贡献 + 10&
好...........
威望3011 在线时间7971 小时金币26923 贡献2114 存款 最后登录注册时间帖子精华3积分5140阅读权限100UID133418
TA的每日心情奋斗3&天前签到天数: 1466 天[LV.10]以坛为家III金币26923 贡献2114 存款 威望3011 最后登录帖子积分5140注册时间UID133418
好经验,给你加分了
威望398 在线时间898 小时金币69271 贡献743 存款0 最后登录注册时间帖子精华0积分1141阅读权限80UID155684
项目经理, 积分 1141, 距离下一级还需 359 积分
TA的每日心情开心 10:25:36签到天数: 427 天[LV.9]以坛为家II金币69271 贡献743 存款0 威望398 最后登录帖子积分1141注册时间UID155684
回复 1# 的帖子
ROM母块校正是啥意思?能讲一下吗?
威望2098 在线时间1515 小时金币126110 贡献722 存款 最后登录注册时间帖子精华0积分2820阅读权限100UID136102
TA的每日心情开心 09:59:49签到天数: 2 天[LV.1]初来乍到金币126110 贡献722 存款 威望2098 最后登录帖子积分2820注册时间UID136102
好经验,给你加分了
热心助人,论坛有您更精彩!
总评分:&威望 + 10&
贡献 + 10&
威望1411 在线时间1061 小时金币1037322 贡献110 存款0 最后登录注册时间帖子精华2积分1531阅读权限100UID114422
该用户从未签到金币1037322 贡献110 存款0 威望1411 最后登录帖子积分1531注册时间UID114422
修好了就是技术,走一点弯路很正常,感谢分享
感谢分享,论坛有您更精彩!
总评分:&威望 + 10&
贡献 + 10&
有了朋友们的支持,我会走得更远,愿好人一生平安
威望3011 在线时间7971 小时金币26923 贡献2114 存款 最后登录注册时间帖子精华3积分5140阅读权限100UID133418
TA的每日心情奋斗3&天前签到天数: 1466 天[LV.10]以坛为家III金币26923 贡献2114 存款 威望3011 最后登录帖子积分5140注册时间UID133418
你故障机是行包坏,你换行包不符供电有差异,要是换个正品就没事了,
威望12278 在线时间6781 小时金币57640 贡献4737 存款3278888 最后登录注册时间帖子精华0积分17015阅读权限101UID171016
TA的每日心情开心昨天&10:57签到天数: 2128 天[LV.Master]伴坛终老金币57640 贡献4737 存款3278888 威望12278 最后登录帖子积分17015注册时间UID171016
弯路不怕走,& &&&只要搞定就是高手.& &
威望985 在线时间297 小时金币536438 贡献281 存款0 最后登录注册时间帖子精华0积分1266阅读权限80UID202133
项目经理, 积分 1266, 距离下一级还需 234 积分
TA的每日心情慵懒 10:24:23签到天数: 5 天[LV.2]偶尔看看I金币536438 贡献281 存款0 威望985 最后登录帖子积分1266注册时间UID202133
精品文章,论坛有您更精彩!
威望3011 在线时间7971 小时金币26923 贡献2114 存款 最后登录注册时间帖子精华3积分5140阅读权限100UID133418
TA的每日心情奋斗3&天前签到天数: 1466 天[LV.10]以坛为家III金币26923 贡献2114 存款 威望3011 最后登录帖子积分5140注册时间UID133418
大家有好的经验发上来
163DZ荣誉:最佳新人奖
163DZ荣誉:最佳新人奖
163DZ荣誉:优秀版主
163DZ荣誉:优秀版主
163DZ荣誉:最佳人气奖
163DZ荣誉:最佳人气奖
Powered byGoogle-Guava Concurrent包里的Service框架浅析
Google-Guava Concurrent包里的Service框架浅析
译文地址 译者:何一昕 校对:方腾飞
Guava包里的Service接口用于封装一个服务对象的运行状态、包括start和stop等方法。例如web服务器,RPC服务器、计时器等可以实现这个接口。
译者:何一昕 校对:方腾飞
Guava包里的Service接口用于封装一个服务对象的运行状态、包括start和stop等方法。例如web服务器,RPC服务器、计时器等可以实现这个接口。对此类服务的状态管理并不轻松、需要对服务的开启/关闭进行妥善管理、特别是在多线程环境下尤为复杂。Guava包提供了一些基础类帮助你管理复杂的状态转换逻辑和同步细节。
使用一个服务
一个服务正常生命周期有:
服务一旦被停止就无法再重新启动了。如果服务在starting、running、stopping状态出现问题、会进入.状态。调用 方法可以异步开启一个服务,同时返回this对象形成方法调用链。注意:只有在当前服务的状态是时才能调用startAsync()方法,因此最好在应用中有一个统一的地方初始化相关服务。停止一个服务也是类似的、使用异步方法 。但是不像startAsync(),多次调用这个方法是安全的。这是为了方便处理关闭服务时候的锁竞争问题。
Service也提供了一些方法用于等待服务状态转换的完成:
通过 方法异步添加监听器。此方法允许你添加一个
、它会在每次服务状态转换的时候被调用。注意:最好在服务启动之前添加Listener(这时的状态是NEW)、否则之前已发生的状态转换事件是无法在新添加的Listener上被重新触发的。
同步使用。这个方法不能被打断、不强制捕获异常、一旦服务启动就会返回。如果服务没有成功启动,会抛出IllegalStateException异常。同样的,
方法会等待服务达到终止状态( 或者 )。两个方法都有重载方法允许传入超时时间。
接口本身实现起来会比较复杂、且容易碰到一些捉摸不透的问题。因此我们不推荐直接实现这个接口。而是请继承Guava包里已经封装好的基础抽象类。每个基础类支持一种特定的线程模型。
基础实现类
AbstractIdleService
类简单实现了Service接口、其在running状态时不会执行任何动作–因此在running时也不需要启动线程–但需要处理开启/关闭动作。要实现一个此类的服务,只需继承AbstractIdleService类,然后自己实现 和方法就可以了。
protected void startUp() {
servlets.add(new GcStatsServlet());
protected void shutDown() {}
如上面的例子、由于任何请求到GcStatsServlet时已经会有现成线程处理了,所以在服务运行时就不需要做什么额外动作了。
AbstractExecutionThreadService
通过单线程处理启动、运行、和关闭等操作。你必须重载run()方法,同时需要能响应停止服务的请求。具体的实现可以在一个循环内做处理:
public void run() {
while (isRunning()) {
另外,你还可以重载方法让run()方法结束返回。
重载startUp()和shutDown()方法是可选的,不影响服务本身状态的管理
protected void startUp() {
dispatcher.listenForConnections(port, queue);
protected void run() {
while ((connection = queue.take() != POISON)) {
process(connection);
protected void triggerShutdown() {
dispatcher.stopListeningForConnections(queue);
queue.put(POISON);
start()内部会调用startUp()方法,创建一个线程、然后在线程内调用run()方法。stop()会调用 triggerShutdown()方法并且等待线程终止。
AbstractScheduledService
类用于在运行时处理一些周期性的任务。子类可以实现 方法定义一个周期执行的任务,以及相应的startUp()和shutDown()方法。为了能够描述执行周期,你需要实现方法。通常情况下,你可以使用类提供的两种调度器:
和,类似于JDK并发包中ScheduledExecutorService类提供的两种调度方式。如要自定义schedules则可以使用 类来辅助实现;具体用法见javadoc。
AbstractService
如需要自定义的线程管理、可以通过扩展 类来实现。一般情况下、使用上面的几个实现类就已经满足需求了,但如果在服务执行过程中有一些特定的线程处理需求、则建议继承AbstractService类。
继承AbstractService方法必须实现两个方法.
首次调用startAsync()时会同时调用doStart(),doStart()内部需要处理所有的初始化工作、如果启动成功则调用方法;启动失败则调用
首次调用stopAsync()会同时调用doStop(),doStop()要做的事情就是停止服务,如果停止成功则调用 方法;停止失败则调用 方法。
doStart和doStop方法的实现需要考虑下性能,尽可能的低延迟。如果初始化的开销较大,如读文件,打开网络连接,或者其他任何可能引起阻塞的操作,建议移到另外一个单独的线程去处理。
使用ServiceManager
除了对Service接口提供基础的实现类,Guava还提供了 类使得涉及到多个Service集合的操作更加容易。通过实例化ServiceManager类来创建一个Service集合,你可以通过以下方法来管理它们:
: 将启动所有被管理的服务。如果当前服务的状态都是NEW的话、那么你只能调用该方法一次、这跟 Service#startAsync()是一样的。
:将停止所有被管理的服务。
:会添加一个,在服务状态转换中会调用该Listener
:会等待所有的服务达到Running状态
:会等待所有服务达到终止状态
检测类的方法有:
:如果所有的服务处于Running状态、会返回True
:以状态为索引返回当前所有服务的快照
:返回一个Map对象,记录被管理的服务启动的耗时、以毫秒为单位,同时Map默认按启动时间排序。
我们建议整个服务的生命周期都能通过ServiceManager来管理,不过即使状态转换是通过其他机制触发的、也不影响ServiceManager方法的正确执行。例如:当一个服务不是通过startAsync()、而是其他机制启动时,listeners 仍然可以被正常调用、awaitHealthy()也能够正常工作。ServiceManager 唯一强制的要求是当其被创建时所有的服务必须处于New状态。
附:TestCase、也可以作为练习Demo
ServiceTest
public void testStateOrdering() {
assertLessThan(NEW, STARTING);
assertLessThan(NEW, TERMINATED);
assertLessThan(STARTING, RUNNING);
assertLessThan(STARTING, STOPPING);
assertLessThan(STARTING, FAILED);
assertLessThan(RUNNING, STOPPING);
assertLessThan(RUNNING, FAILED);
assertLessThan(STOPPING, FAILED);
assertLessThan(STOPPING, TERMINATED);
private static &T extends Comparable&? super T&& void assertLessThan(T a, T b) {
if (a.compareTo(b) &= 0) {
fail(String.format("Expected %s to be less than %s", a, b));
AbstractIdleServiceTest
public class AbstractIdleServiceTest extends TestCase {
public static class FunctionalTest extends TestCase {
private static class DefaultService extends AbstractIdleService {
@Override protected void startUp() throws Exception {}
@Override protected void shutDown() throws Exception {}
public void testServiceStartStop() throws Exception {
AbstractIdleService service = new DefaultService();
service.startAsync().awaitRunning();
assertEquals(Service.State.RUNNING, service.state());
service.stopAsync().awaitTerminated();
assertEquals(Service.State.TERMINATED, service.state());
public void testStart_failed() throws Exception {
final Exception exception = new Exception("deliberate");
AbstractIdleService service = new DefaultService() {
@Override protected void startUp() throws Exception {
service.startAsync().awaitRunning();
} catch (RuntimeException e) {
assertSame(exception, e.getCause());
assertEquals(Service.State.FAILED, service.state());
public void testStop_failed() throws Exception {
final Exception exception = new Exception("deliberate");
AbstractIdleService service = new DefaultService() {
@Override protected void shutDown() throws Exception {
service.startAsync().awaitRunning();
service.stopAsync().awaitTerminated();
} catch (RuntimeException e) {
assertSame(exception, e.getCause());
assertEquals(Service.State.FAILED, service.state());
public void testStart() {
TestService service = new TestService();
assertEquals(0, service.startUpCalled);
service.startAsync().awaitRunning();
assertEquals(1, service.startUpCalled);
assertEquals(Service.State.RUNNING, service.state());
ASSERT.that(service.transitionStates).has().exactly(Service.State.STARTING).inOrder();
public void testStart_failed() {
final Exception exception = new Exception("deliberate");
TestService service = new TestService() {
@Override protected void startUp() throws Exception {
super.startUp();
assertEquals(0, service.startUpCalled);
service.startAsync().awaitRunning();
} catch (RuntimeException e) {
assertSame(exception, e.getCause());
assertEquals(1, service.startUpCalled);
assertEquals(Service.State.FAILED, service.state());
ASSERT.that(service.transitionStates).has().exactly(Service.State.STARTING).inOrder();
public void testStop_withoutStart() {
TestService service = new TestService();
service.stopAsync().awaitTerminated();
assertEquals(0, service.startUpCalled);
assertEquals(0, service.shutDownCalled);
assertEquals(Service.State.TERMINATED, service.state());
ASSERT.that(service.transitionStates).isEmpty();
public void testStop_afterStart() {
TestService service = new TestService();
service.startAsync().awaitRunning();
assertEquals(1, service.startUpCalled);
assertEquals(0, service.shutDownCalled);
service.stopAsync().awaitTerminated();
assertEquals(1, service.startUpCalled);
assertEquals(1, service.shutDownCalled);
assertEquals(Service.State.TERMINATED, service.state());
ASSERT.that(service.transitionStates)
.has().exactly(Service.State.STARTING, Service.State.STOPPING).inOrder();
public void testStop_failed() {
final Exception exception = new Exception("deliberate");
TestService service = new TestService() {
@Override protected void shutDown() throws Exception {
super.shutDown();
service.startAsync().awaitRunning();
assertEquals(1, service.startUpCalled);
assertEquals(0, service.shutDownCalled);
service.stopAsync().awaitTerminated();
} catch (RuntimeException e) {
assertSame(exception, e.getCause());
assertEquals(1, service.startUpCalled);
assertEquals(1, service.shutDownCalled);
assertEquals(Service.State.FAILED, service.state());
ASSERT.that(service.transitionStates)
.has().exactly(Service.State.STARTING, Service.State.STOPPING).inOrder();
public void testServiceToString() {
AbstractIdleService service = new TestService();
assertEquals("TestService [NEW]", service.toString());
service.startAsync().awaitRunning();
assertEquals("TestService [RUNNING]", service.toString());
service.stopAsync().awaitTerminated();
assertEquals("TestService [TERMINATED]", service.toString());
public void testTimeout() throws Exception {
Service service = new TestService() {
@Override protected Executor executor() {
return new Executor() {
@Override public void execute(Runnable command) {}
service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS);
fail("Expected timeout");
} catch (TimeoutException e) {
ASSERT.that(e.getMessage()).contains(Service.State.STARTING.toString());
private static class TestService extends AbstractIdleService {
int startUpCalled = 0;
int shutDownCalled = 0;
final List&State& transitionStates = Lists.newArrayList();
@Override protected void startUp() throws Exception {
assertEquals(0, startUpCalled);
assertEquals(0, shutDownCalled);
startUpCalled++;
assertEquals(State.STARTING, state());
@Override protected void shutDown() throws Exception {
assertEquals(1, startUpCalled);
assertEquals(0, shutDownCalled);
shutDownCalled++;
assertEquals(State.STOPPING, state());
@Override protected Executor executor() {
transitionStates.add(state());
return MoreExecutors.sameThreadExecutor();
AbstractScheduledServiceTest
public class AbstractScheduledServiceTest extends TestCase {
volatile Scheduler configuration = Scheduler.newFixedDelaySchedule(0, 10, TimeUnit.MILLISECONDS);
volatile ScheduledFuture&?& future = null;
volatile boolean atFixedRateCalled = false;
volatile boolean withFixedDelayCalled = false;
volatile boolean scheduleCalled = false;
final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(10) {
public ScheduledFuture&?& scheduleWithFixedDelay(Runnable command, long initialDelay,
long delay, TimeUnit unit) {
return future = super.scheduleWithFixedDelay(command, initialDelay, delay, unit);
public void testServiceStartStop() throws Exception {
NullService service = new NullService();
service.startAsync().awaitRunning();
assertFalse(future.isDone());
service.stopAsync().awaitTerminated();
assertTrue(future.isCancelled());
private class NullService extends AbstractScheduledService {
@Override protected void runOneIteration() throws Exception {}
@Override protected Scheduler scheduler() { return
@Override protected ScheduledExecutorService executor() { return
public void testFailOnExceptionFromRun() throws Exception {
TestService service = new TestService();
service.runException = new Exception();
service.startAsync().awaitRunning();
service.runFirstBarrier.await();
service.runSecondBarrier.await();
future.get();
} catch (ExecutionException e) {
assertEquals(service.runException, e.getCause().getCause());
assertEquals(service.state(), Service.State.FAILED);
public void testFailOnExceptionFromStartUp() {
TestService service = new TestService();
service.startUpException = new Exception();
service.startAsync().awaitRunning();
} catch (IllegalStateException e) {
assertEquals(service.startUpException, e.getCause());
assertEquals(0, service.numberOfTimesRunCalled.get());
assertEquals(Service.State.FAILED, service.state());
public void testFailOnExceptionFromShutDown() throws Exception {
TestService service = new TestService();
service.shutDownException = new Exception();
service.startAsync().awaitRunning();
service.runFirstBarrier.await();
service.stopAsync();
service.runSecondBarrier.await();
service.awaitTerminated();
} catch (IllegalStateException e) {
assertEquals(service.shutDownException, e.getCause());
assertEquals(Service.State.FAILED, service.state());
public void testRunOneIterationCalledMultipleTimes() throws Exception {
TestService service = new TestService();
service.startAsync().awaitRunning();
for (int i = 1; i & 10; i++) {
service.runFirstBarrier.await();
assertEquals(i, service.numberOfTimesRunCalled.get());
service.runSecondBarrier.await();
service.runFirstBarrier.await();
service.stopAsync();
service.runSecondBarrier.await();
service.stopAsync().awaitTerminated();
public void testExecutorOnlyCalledOnce() throws Exception {
TestService service = new TestService();
service.startAsync().awaitRunning();
assertEquals(1, service.numberOfTimesExecutorCalled.get());
for (int i = 1; i & 10; i++) {
service.runFirstBarrier.await();
assertEquals(i, service.numberOfTimesRunCalled.get());
service.runSecondBarrier.await();
service.runFirstBarrier.await();
service.stopAsync();
service.runSecondBarrier.await();
service.stopAsync().awaitTerminated();
assertEquals(1, service.numberOfTimesExecutorCalled.get());
public void testDefaultExecutorIsShutdownWhenServiceIsStopped() throws Exception {
final CountDownLatch terminationLatch = new CountDownLatch(1);
AbstractScheduledService service = new AbstractScheduledService() {
volatile ScheduledExecutorService executorS
@Override protected void runOneIteration() throws Exception {}
@Override protected ScheduledExecutorService executor() {
if (executorService == null) {
executorService = super.executor();
addListener(new Listener() {
@Override public void terminated(State from) {
terminationLatch.countDown();
}, MoreExecutors.sameThreadExecutor());
return executorS
@Override protected Scheduler scheduler() {
return Scheduler.newFixedDelaySchedule(0, 1, TimeUnit.MILLISECONDS);
service.startAsync();
assertFalse(service.executor().isShutdown());
service.awaitRunning();
service.stopAsync();
terminationLatch.await();
assertTrue(service.executor().isShutdown());
assertTrue(service.executor().awaitTermination(100, TimeUnit.MILLISECONDS));
public void testDefaultExecutorIsShutdownWhenServiceFails() throws Exception {
final CountDownLatch failureLatch = new CountDownLatch(1);
AbstractScheduledService service = new AbstractScheduledService() {
volatile ScheduledExecutorService executorS
@Override protected void runOneIteration() throws Exception {}
@Override protected void startUp() throws Exception {
throw new Exception("Failed");
@Override protected ScheduledExecutorService executor() {
if (executorService == null) {
executorService = super.executor();
addListener(new Listener() {
@Override public void failed(State from, Throwable failure) {
failureLatch.countDown();
}, MoreExecutors.sameThreadExecutor());
return executorS
@Override protected Scheduler scheduler() {
return Scheduler.newFixedDelaySchedule(0, 1, TimeUnit.MILLISECONDS);
service.startAsync().awaitRunning();
fail("Expected service to fail during startup");
} catch (IllegalStateException expected) {}
failureLatch.await();
assertTrue(service.executor().isShutdown());
assertTrue(service.executor().awaitTermination(100, TimeUnit.MILLISECONDS));
public void testSchedulerOnlyCalledOnce() throws Exception {
TestService service = new TestService();
service.startAsync().awaitRunning();
assertEquals(1, service.numberOfTimesSchedulerCalled.get());
for (int i = 1; i & 10; i++) {
service.runFirstBarrier.await();
assertEquals(i, service.numberOfTimesRunCalled.get());
service.runSecondBarrier.await();
service.runFirstBarrier.await();
service.stopAsync();
service.runSecondBarrier.await();
service.awaitTerminated();
assertEquals(1, service.numberOfTimesSchedulerCalled.get());
private class TestService extends AbstractScheduledService {
CyclicBarrier runFirstBarrier = new CyclicBarrier(2);
CyclicBarrier runSecondBarrier = new CyclicBarrier(2);
volatile boolean startUpCalled = false;
volatile boolean shutDownCalled = false;
AtomicInteger numberOfTimesRunCalled = new AtomicInteger(0);
AtomicInteger numberOfTimesExecutorCalled = new AtomicInteger(0);
AtomicInteger numberOfTimesSchedulerCalled = new AtomicInteger(0);
volatile Exception runException = null;
volatile Exception startUpException = null;
volatile Exception shutDownException = null;
protected void runOneIteration() throws Exception {
assertTrue(startUpCalled);
assertFalse(shutDownCalled);
numberOfTimesRunCalled.incrementAndGet();
assertEquals(State.RUNNING, state());
runFirstBarrier.await();
runSecondBarrier.await();
if (runException != null) {
throw runE
protected void startUp() throws Exception {
assertFalse(startUpCalled);
assertFalse(shutDownCalled);
startUpCalled = true;
assertEquals(State.STARTING, state());
if (startUpException != null) {
throw startUpE
protected void shutDown() throws Exception {
assertTrue(startUpCalled);
assertFalse(shutDownCalled);
shutDownCalled = true;
if (shutDownException != null) {
throw shutDownE
protected ScheduledExecutorService executor() {
numberOfTimesExecutorCalled.incrementAndGet();
protected Scheduler scheduler() {
numberOfTimesSchedulerCalled.incrementAndGet();
public static class SchedulerTest extends TestCase {
private static final int initialDelay = 10;
private static final int delay = 20;
private static final TimeUnit unit = TimeUnit.MILLISECONDS;
final Runnable testRunnable = new Runnable() {@Override public void run() {}};
boolean called = false;
private void assertSingleCallWithCorrectParameters(Runnable command, long initialDelay,
long delay, TimeUnit unit) {
assertFalse(called);
called = true;
assertEquals(SchedulerTest.initialDelay, initialDelay);
assertEquals(SchedulerTest.delay, delay);
assertEquals(SchedulerTest.unit, unit);
assertEquals(testRunnable, command);
public void testFixedRateSchedule() {
Scheduler schedule = Scheduler.newFixedRateSchedule(initialDelay, delay, unit);
schedule.schedule(null, new ScheduledThreadPoolExecutor(1) {
public ScheduledFuture&?& scheduleAtFixedRate(Runnable command, long initialDelay,
long period, TimeUnit unit) {
assertSingleCallWithCorrectParameters(command, initialDelay, delay, unit);
return null;
}, testRunnable);
assertTrue(called);
public void testFixedDelaySchedule() {
Scheduler schedule = Scheduler.newFixedDelaySchedule(initialDelay, delay, unit);
schedule.schedule(null, new ScheduledThreadPoolExecutor(10) {
public ScheduledFuture&?& scheduleWithFixedDelay(Runnable command, long initialDelay,
long delay, TimeUnit unit) {
assertSingleCallWithCorrectParameters(command, initialDelay, delay, unit);
return null;
}, testRunnable);
assertTrue(called);
private class TestCustomScheduler extends AbstractScheduledService.CustomScheduler {
public AtomicInteger scheduleCounter = new AtomicInteger(0);
protected Schedule getNextSchedule() throws Exception {
scheduleCounter.incrementAndGet();
return new Schedule(0, TimeUnit.SECONDS);
public void testCustomSchedule_startStop() throws Exception {
final CyclicBarrier firstBarrier = new CyclicBarrier(2);
final CyclicBarrier secondBarrier = new CyclicBarrier(2);
final AtomicBoolean shouldWait = new AtomicBoolean(true);
Runnable task = new Runnable() {
@Override public void run() {
if (shouldWait.get()) {
firstBarrier.await();
secondBarrier.await();
} catch (Exception e) {
throw new RuntimeException(e);
TestCustomScheduler scheduler = new TestCustomScheduler();
Future&?& future = scheduler.schedule(null, Executors.newScheduledThreadPool(10), task);
firstBarrier.await();
assertEquals(1, scheduler.scheduleCounter.get());
secondBarrier.await();
firstBarrier.await();
assertEquals(2, scheduler.scheduleCounter.get());
shouldWait.set(false);
secondBarrier.await();
future.cancel(false);
public void testCustomSchedulerServiceStop() throws Exception {
TestAbstractScheduledCustomService service = new TestAbstractScheduledCustomService();
service.startAsync().awaitRunning();
service.firstBarrier.await();
assertEquals(1, service.numIterations.get());
service.stopAsync();
service.secondBarrier.await();
service.awaitTerminated();
Thread.sleep(unit.toMillis(3 * delay));
assertEquals(1, service.numIterations.get());
public void testBig() throws Exception {
TestAbstractScheduledCustomService service = new TestAbstractScheduledCustomService() {
@Override protected Scheduler scheduler() {
return new AbstractScheduledService.CustomScheduler() {
protected Schedule getNextSchedule() throws Exception {
Thread.yield();
return new Schedule(0, TimeUnit.SECONDS);
service.useBarriers = false;
service.startAsync().awaitRunning();
Thread.sleep(50);
service.useBarriers = true;
service.firstBarrier.await();
int numIterations = service.numIterations.get();
service.stopAsync();
service.secondBarrier.await();
service.awaitTerminated();
assertEquals(numIterations, service.numIterations.get());
private static class TestAbstractScheduledCustomService extends AbstractScheduledService {
final AtomicInteger numIterations = new AtomicInteger(0);
volatile boolean useBarriers = true;
final CyclicBarrier firstBarrier = new CyclicBarrier(2);
final CyclicBarrier secondBarrier = new CyclicBarrier(2);
@Override protected void runOneIteration() throws Exception {
numIterations.incrementAndGet();
if (useBarriers) {
firstBarrier.await();
secondBarrier.await();
@Override protected ScheduledExecutorService executor() {
return Executors.newScheduledThreadPool(10);
@Override protected void startUp() throws Exception {}
@Override protected void shutDown() throws Exception {}
@Override protected Scheduler scheduler() {
return new CustomScheduler() {
protected Schedule getNextSchedule() throws Exception {
return new Schedule(delay, unit);
public void testCustomSchedulerFailure() throws Exception {
TestFailingCustomScheduledService service = new TestFailingCustomScheduledService();
service.startAsync().awaitRunning();
for (int i = 1; i & 4; i++) {
service.firstBarrier.await();
assertEquals(i, service.numIterations.get());
service.secondBarrier.await();
Thread.sleep(1000);
service.stopAsync().awaitTerminated(100, TimeUnit.SECONDS);
} catch (IllegalStateException e) {
assertEquals(State.FAILED, service.state());
private static class TestFailingCustomScheduledService extends AbstractScheduledService {
final AtomicInteger numIterations = new AtomicInteger(0);
final CyclicBarrier firstBarrier = new CyclicBarrier(2);
final CyclicBarrier secondBarrier = new CyclicBarrier(2);
@Override protected void runOneIteration() throws Exception {
numIterations.incrementAndGet();
firstBarrier.await();
secondBarrier.await();
@Override protected ScheduledExecutorService executor() {
return Executors.newScheduledThreadPool(10);
@Override protected Scheduler scheduler() {
return new CustomScheduler() {
protected Schedule getNextSchedule() throws Exception {
if (numIterations.get() & 2) {
throw new IllegalStateException("Failed");
return new Schedule(delay, unit);
AbstractServiceTest
void awaitRunChecks() throws InterruptedException {
assertTrue("Service thread hasn't finished its checks. "
+ "Exception status (possibly stale): " + thrownByExecutionThread,
hasConfirmedIsRunning.await(10, SECONDS));
@Override protected void doStart() {
assertEquals(State.STARTING, state());
invokeOnExecutionThreadForTest(new Runnable() {
@Override public void run() {
assertEquals(State.STARTING, state());
notifyStarted();
assertEquals(State.RUNNING, state());
hasConfirmedIsRunning.countDown();
@Override protected void doStop() {
assertEquals(State.STOPPING, state());
invokeOnExecutionThreadForTest(new Runnable() {
@Override public void run() {
assertEquals(State.STOPPING, state());
notifyStopped();
assertEquals(State.TERMINATED, state());
private void invokeOnExecutionThreadForTest(Runnable runnable) {
executionThread = new Thread(runnable);
executionThread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable e) {
thrownByExecutionThread =
executionThread.start();
private static void throwIfSet(Throwable t) throws Throwable {
if (t != null) {
public void testStopUnstartedService() throws Exception {
NoOpService service = new NoOpService();
RecordingListener listener = RecordingListener.record(service);
service.stopAsync();
assertEquals(State.TERMINATED, service.state());
service.startAsync();
} catch (IllegalStateException expected) {}
assertEquals(State.TERMINATED, Iterables.getOnlyElement(listener.getStateHistory()));
public void testFailingServiceStartAndWait() throws Exception {
StartFailingService service = new StartFailingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync().awaitRunning();
} catch (IllegalStateException e) {
assertEquals(EXCEPTION, service.failureCause());
assertEquals(EXCEPTION, e.getCause());
assertEquals(
ImmutableList.of(
State.STARTING,
State.FAILED),
listener.getStateHistory());
public void testFailingServiceStopAndWait_stopFailing() throws Exception {
StopFailingService service = new StopFailingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync().awaitRunning();
service.stopAsync().awaitTerminated();
} catch (IllegalStateException e) {
assertEquals(EXCEPTION, service.failureCause());
assertEquals(EXCEPTION, e.getCause());
assertEquals(
ImmutableList.of(
State.STARTING,
State.RUNNING,
State.STOPPING,
State.FAILED),
listener.getStateHistory());
public void testFailingServiceStopAndWait_runFailing() throws Exception {
RunFailingService service = new RunFailingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync();
service.awaitRunning();
} catch (IllegalStateException e) {
assertEquals(EXCEPTION, service.failureCause());
assertEquals(EXCEPTION, e.getCause());
assertEquals(
ImmutableList.of(
State.STARTING,
State.RUNNING,
State.FAILED),
listener.getStateHistory());
public void testThrowingServiceStartAndWait() throws Exception {
StartThrowingService service = new StartThrowingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync().awaitRunning();
} catch (IllegalStateException e) {
assertEquals(service.exception, service.failureCause());
assertEquals(service.exception, e.getCause());
assertEquals(
ImmutableList.of(
State.STARTING,
State.FAILED),
listener.getStateHistory());
public void testThrowingServiceStopAndWait_stopThrowing() throws Exception {
StopThrowingService service = new StopThrowingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync().awaitRunning();
service.stopAsync().awaitTerminated();
} catch (IllegalStateException e) {
assertEquals(service.exception, service.failureCause());
assertEquals(service.exception, e.getCause());
assertEquals(
ImmutableList.of(
State.STARTING,
State.RUNNING,
State.STOPPING,
State.FAILED),
listener.getStateHistory());
public void testThrowingServiceStopAndWait_runThrowing() throws Exception {
RunThrowingService service = new RunThrowingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync();
service.awaitTerminated();
} catch (IllegalStateException e) {
assertEquals(service.exception, service.failureCause());
assertEquals(service.exception, e.getCause());
assertEquals(
ImmutableList.of(
State.STARTING,
State.RUNNING,
State.FAILED),
listener.getStateHistory());
public void testFailureCause_throwsIfNotFailed() {
StopFailingService service = new StopFailingService();
service.failureCause();
} catch (IllegalStateException e) {
service.startAsync().awaitRunning();
service.failureCause();
} catch (IllegalStateException e) {
service.stopAsync().awaitTerminated();
} catch (IllegalStateException e) {
assertEquals(EXCEPTION, service.failureCause());
assertEquals(EXCEPTION, e.getCause());
public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
final StartFailingService service = new StartFailingService();
service.startAsync();
assertEquals(State.FAILED, service.state());
service.addListener(new RecordingListener(service), MoreExecutors.sameThreadExecutor());
Thread thread = new Thread() {
@Override public void run() {
service.stopAsync();
thread.start();
thread.join(100);
assertFalse(thread + " is deadlocked", thread.isAlive());
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
final NoOpThreadedService service = new NoOpThreadedService();
service.addListener(new Listener() {
@Override public void running() {
service.awaitRunning();
}, MoreExecutors.sameThreadExecutor());
service.startAsync().awaitRunning(10, TimeUnit.MILLISECONDS);
service.stopAsync();
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
final NoOpThreadedService service = new NoOpThreadedService();
service.addListener(new Listener() {
@Override public void terminated(State from) {
service.stopAsync().awaitTerminated();
}, MoreExecutors.sameThreadExecutor());
service.startAsync().awaitRunning();
Thread thread = new Thread() {
@Override public void run() {
service.stopAsync().awaitTerminated();
thread.start();
thread.join(100);
assertFalse(thread + " is deadlocked", thread.isAlive());
private static class NoOpThreadedService extends AbstractExecutionThreadService {
final CountDownLatch latch = new CountDownLatch(1);
@Override protected void run() throws Exception {
latch.await();
@Override protected void triggerShutdown() {
latch.countDown();
private static class StartFailingService extends AbstractService {
@Override protected void doStart() {
notifyFailed(EXCEPTION);
@Override protected void doStop() {
private static class RunFailingService extends AbstractService {
@Override protected void doStart() {
notifyStarted();
notifyFailed(EXCEPTION);
@Override protected void doStop() {
private static class StopFailingService extends AbstractService {
@Override protected void doStart() {
notifyStarted();
@Override protected void doStop() {
notifyFailed(EXCEPTION);
private static class StartThrowingService extends AbstractService {
final RuntimeException exception = new RuntimeException("deliberate");
@Override protected void doStart() {
@Override protected void doStop() {
private static class RunThrowingService extends AbstractService {
final RuntimeException exception = new RuntimeException("deliberate");
@Override protected void doStart() {
notifyStarted();
@Override protected void doStop() {
private static class StopThrowingService extends AbstractService {
final RuntimeException exception = new RuntimeException("deliberate");
@Override protected void doStart() {
notifyStarted();
@Override protected void doStop() {
private static class RecordingListener extends Listener {
static RecordingListener record(Service service) {
RecordingListener listener = new RecordingListener(service);
service.addListener(listener, MoreExecutors.sameThreadExecutor());
RecordingListener(Service service) {
this.service =
@GuardedBy("this")
final List&State& stateHistory = Lists.newArrayList();
final CountDownLatch completionLatch = new CountDownLatch(1);
ImmutableList&State& getStateHistory() throws Exception {
completionLatch.await();
synchronized (this) {
return ImmutableList.copyOf(stateHistory);
@Override public synchronized void starting() {
assertTrue(stateHistory.isEmpty());
assertNotSame(State.NEW, service.state());
stateHistory.add(State.STARTING);
@Override public synchronized void running() {
assertEquals(State.STARTING, Iterables.getOnlyElement(stateHistory));
stateHistory.add(State.RUNNING);
service.awaitRunning();
assertNotSame(State.STARTING, service.state());
@Override public synchronized void stopping(State from) {
assertEquals(from, Iterables.getLast(stateHistory));
stateHistory.add(State.STOPPING);
if (from == State.STARTING) {
service.awaitRunning();
} catch (IllegalStateException expected) {
assertNull(expected.getCause());
assertTrue(expected.getMessage().equals(
"Expected the service to be RUNNING, but was STOPPING"));
assertNotSame(from, service.state());
@Override public synchronized void terminated(State from) {
assertEquals(from, Iterables.getLast(stateHistory, State.NEW));
stateHistory.add(State.TERMINATED);
assertEquals(State.TERMINATED, service.state());
if (from == State.NEW) {
service.awaitRunning();
} catch (IllegalStateException expected) {
assertNull(expected.getCause());
assertTrue(expected.getMessage().equals(
"Expected the service to be RUNNING, but was TERMINATED"));
completionLatch.countDown();
@Override public synchronized void failed(State from, Throwable failure) {
assertEquals(from, Iterables.getLast(stateHistory));
stateHistory.add(State.FAILED);
assertEquals(State.FAILED, service.state());
assertEquals(failure, service.failureCause());
if (from == State.STARTING) {
service.awaitRunning();
} catch (IllegalStateException e) {
assertEquals(failure, e.getCause());
service.awaitTerminated();
} catch (IllegalStateException e) {
assertEquals(failure, e.getCause());
completionLatch.countDown();
public void testNotifyStartedWhenNotStarting() {
AbstractService service = new DefaultService();
service.notifyStarted();
} catch (IllegalStateException expected) {}
public void testNotifyStoppedWhenNotRunning() {
AbstractService service = new DefaultService();
service.notifyStopped();
} catch (IllegalStateException expected) {}
public void testNotifyFailedWhenNotStarted() {
AbstractService service = new DefaultService();
service.notifyFailed(new Exception());
} catch (IllegalStateException expected) {}
public void testNotifyFailedWhenTerminated() {
NoOpService service = new NoOpService();
service.startAsync().awaitRunning();
service.stopAsync().awaitTerminated();
service.notifyFailed(new Exception());
} catch (IllegalStateException expected) {}
private static class DefaultService extends AbstractService {
@Override protected void doStart() {}
@Override protected void doStop() {}
private static final Exception EXCEPTION = new Exception();
ServiceManagerTest
private static class SnappyShutdownService extends AbstractExecutionThreadService {
final CountDownLatch latch = new CountDownLatch(1);
SnappyShutdownService(int index) {
this.index =
@Override protected void run() throws Exception {
latch.await();
@Override protected void triggerShutdown() {
latch.countDown();
@Override protected String serviceName() {
return this.getClass().getSimpleName() + "[" + index + "]";
public void testNulls() {
ServiceManager manager = new ServiceManager(Arrays.&Service&asList());
new NullPointerTester()
.setDefault(ServiceManager.Listener.class, new RecordingListener())
.testAllPublicInstanceMethods(manager);
private static final class RecordingListener extends ServiceManager.Listener {
volatile boolean healthyC
volatile boolean stoppedC
final Set&Service& failedServices = Sets.newConcurrentHashSet();
@Override public void healthy() {
healthyCalled = true;
@Override public void stopped() {
stoppedCalled = true;
@Override public void failure(Service service) {
failedServices.add(service);
用云栖社区APP,舒服~
【云栖快讯】新手小白必看!编程语言系列讲座火爆进行中,与行业资深专家一起学习Python、C++、JavaScript、Java!从入门到进阶&&
是一款提供了现场可编程门阵列(FPGA)的计算实例,基于阿里云弹性计算框架,用户可以几分钟内...
充分利用阿里云现有资源管理和服务体系,引入中间件成熟的整套分布式计算框架,以应用为中心,帮助...
阿里云消息服务(Message Service,原MQS)是阿里云商用的消息中间件服务。与传...
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效...
订阅广场全新上线}

我要回帖

更多关于 www.131.secom 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信