BUG-8618: fix test driver
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / impl / FinalizableScheduledExecutorService.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.clustering.it.provider.impl;
9
10 import java.util.concurrent.ScheduledThreadPoolExecutor;
11 import java.util.concurrent.TimeUnit;
12
13 /**
14  * A simple ScheduledExecutorService, which shutds down its threads after a period of inactivity. It is safe to not
15  * shutdown this
16  *
17  * @author Robert Varga
18  */
19 final class FinalizableScheduledExecutorService extends ScheduledThreadPoolExecutor {
20
21     private FinalizableScheduledExecutorService(final int maxThreads, final long time, final TimeUnit unit) {
22         super(maxThreads);
23         setKeepAliveTime(time, unit);
24         allowCoreThreadTimeOut(true);
25     }
26
27     static ScheduledThreadPoolExecutor newSingleThread() {
28         return new FinalizableScheduledExecutorService(1, 15, TimeUnit.SECONDS);
29     }
30
31     // This is a bit ugly, but allows
32     @Override
33     protected void finalize() {
34         super.shutdownNow();
35     }
36 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.