Search in sources :

Example 1 with Thread

use of java.lang.Thread in project platform_frameworks_base by android.

the class SvcMonitor method startMonitor.

private void startMonitor(Intent intent) {
    if (tMonitor != null) {
        Log.d(TAG, "thread already active");
        return;
    }
    javaProc = intent.getStringExtra("java");
    halProc = intent.getStringExtra("hal");
    period = intent.getIntExtra("period", 1000);
    if (javaProc == null || halProc == null || period < 100) {
        Log.d(TAG, "Failed starting monitor, invalid arguments.");
        stopSelf();
        return;
    }
    Runnable monitor = new MonitorRunnable(this);
    tMonitor = new Thread(monitor);
    tMonitor.start();
}
Also used : Runnable(java.lang.Runnable) Thread(java.lang.Thread)

Example 2 with Thread

use of java.lang.Thread in project android_frameworks_base by AOSPA.

the class SvcMonitor method startMonitor.

private void startMonitor(Intent intent) {
    if (tMonitor != null) {
        Log.d(TAG, "thread already active");
        return;
    }
    javaProc = intent.getStringExtra("java");
    halProc = intent.getStringExtra("hal");
    period = intent.getIntExtra("period", 1000);
    if (javaProc == null || halProc == null || period < 100) {
        Log.d(TAG, "Failed starting monitor, invalid arguments.");
        stopSelf();
        return;
    }
    Runnable monitor = new MonitorRunnable(this);
    tMonitor = new Thread(monitor);
    tMonitor.start();
}
Also used : Runnable(java.lang.Runnable) Thread(java.lang.Thread)

Example 3 with Thread

use of java.lang.Thread in project android_frameworks_base by ResurrectionRemix.

the class SvcMonitor method startMonitor.

private void startMonitor(Intent intent) {
    if (tMonitor != null) {
        Log.d(TAG, "thread already active");
        return;
    }
    javaProc = intent.getStringExtra("java");
    halProc = intent.getStringExtra("hal");
    period = intent.getIntExtra("period", 1000);
    if (javaProc == null || halProc == null || period < 100) {
        Log.d(TAG, "Failed starting monitor, invalid arguments.");
        stopSelf();
        return;
    }
    Runnable monitor = new MonitorRunnable(this);
    tMonitor = new Thread(monitor);
    tMonitor.start();
}
Also used : Runnable(java.lang.Runnable) Thread(java.lang.Thread)

Example 4 with Thread

use of java.lang.Thread in project voltdb by VoltDB.

the class AsyncBenchmark method connect.

/**
     * Connect to a set of servers in parallel. Each will retry until
     * connection. This call will block until all have connected.
     *
     * @param servers
     *            A comma separated list of servers using the hostname:port
     *            syntax (where :port is optional).
     * @throws InterruptedException
     *             if anything bad happens with the threads.
     */
void connect(String servers) throws InterruptedException {
    log.info("Connecting to VoltDB...");
    String[] serverArray = servers.split(",");
    final CountDownLatch connections = new CountDownLatch(serverArray.length);
    // use a new thread to connect to each server
    for (final String server : serverArray) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                connectToOneServerWithRetry(server);
                connections.countDown();
            }
        }).start();
    }
    // block until all have connected
    connections.await();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Thread(java.lang.Thread)

Example 5 with Thread

use of java.lang.Thread in project XobotOS by xamarin.

the class BluetoothAudioGateway method start.

public synchronized boolean start(Handler callback) {
    if (mConnectThead == null) {
        mCallback = callback;
        mConnectThead = new Thread(TAG) {

            public void run() {
                if (DBG)
                    log("Connect Thread starting");
                while (!mInterrupted) {
                    //Log.i(TAG, "waiting for connect");
                    mConnectingHeadsetRfcommChannel = -1;
                    mConnectingHandsfreeRfcommChannel = -1;
                    if (waitForHandsfreeConnectNative(SELECT_WAIT_TIMEOUT) == false) {
                        if (mTimeoutRemainingMs > 0) {
                            try {
                                Log.i(TAG, "select thread timed out, but " + mTimeoutRemainingMs + "ms of waiting remain.");
                                Thread.sleep(mTimeoutRemainingMs);
                            } catch (InterruptedException e) {
                                Log.i(TAG, "select thread was interrupted (2), exiting");
                                mInterrupted = true;
                            }
                        }
                    } else {
                        Log.i(TAG, "connect notification!");
                        /* A device connected (most likely just one, but 
                                   it is possible for two separate devices, one 
                                   a headset and one a handsfree, to connect
                                   simultaneously. 
                                */
                        if (mConnectingHeadsetRfcommChannel >= 0) {
                            Log.i(TAG, "Incoming connection from headset " + mConnectingHeadsetAddress + " on channel " + mConnectingHeadsetRfcommChannel);
                            Message msg = Message.obtain(mCallback);
                            msg.what = MSG_INCOMING_HEADSET_CONNECTION;
                            msg.obj = new IncomingConnectionInfo(mAdapter, mAdapter.getRemoteDevice(mConnectingHeadsetAddress), mConnectingHeadsetSocketFd, mConnectingHeadsetRfcommChannel);
                            msg.sendToTarget();
                        }
                        if (mConnectingHandsfreeRfcommChannel >= 0) {
                            Log.i(TAG, "Incoming connection from handsfree " + mConnectingHandsfreeAddress + " on channel " + mConnectingHandsfreeRfcommChannel);
                            Message msg = Message.obtain();
                            msg.setTarget(mCallback);
                            msg.what = MSG_INCOMING_HANDSFREE_CONNECTION;
                            msg.obj = new IncomingConnectionInfo(mAdapter, mAdapter.getRemoteDevice(mConnectingHandsfreeAddress), mConnectingHandsfreeSocketFd, mConnectingHandsfreeRfcommChannel);
                            msg.sendToTarget();
                        }
                    }
                }
                if (DBG)
                    log("Connect Thread finished");
            }
        };
        if (setUpListeningSocketsNative() == false) {
            Log.e(TAG, "Could not set up listening socket, exiting");
            return false;
        }
        mInterrupted = false;
        mConnectThead.start();
    }
    return true;
}
Also used : Message(android.os.Message) Thread(java.lang.Thread)

Aggregations

Thread (java.lang.Thread)9 Runnable (java.lang.Runnable)5 Message (android.os.Message)1 GraphicsDevice (java.awt.GraphicsDevice)1 CountDownLatch (java.util.concurrent.CountDownLatch)1