mobile/android/base/sync/net/ConnectionMonitorThread.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f5d4f5550907
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.gecko.sync.net;
6
7 import org.mozilla.gecko.background.common.log.Logger;
8
9 /**
10 * Every <code>REAP_INTERVAL</code> milliseconds, wake up
11 * and expire any connections that need cleaning up.
12 *
13 * When we're told to shut down, take the connection manager
14 * with us.
15 */
16 public class ConnectionMonitorThread extends Thread {
17 private static final long REAP_INTERVAL = 5000; // 5 seconds.
18 private static final String LOG_TAG = "ConnectionMonitorThread";
19
20 private volatile boolean stopping;
21
22 @Override
23 public void run() {
24 try {
25 while (!stopping) {
26 synchronized (this) {
27 wait(REAP_INTERVAL);
28 BaseResource.closeExpiredConnections();
29 }
30 }
31 } catch (InterruptedException e) {
32 Logger.trace(LOG_TAG, "Interrupted.");
33 }
34 BaseResource.shutdownConnectionManager();
35 }
36
37 public void shutdown() {
38 Logger.debug(LOG_TAG, "ConnectionMonitorThread told to shut down.");
39 stopping = true;
40 synchronized (this) {
41 notifyAll();
42 }
43 }
44 }

mercurial