本文整理匯總了Java中android.os.Process.myTid方法的典型用法代碼示例。如果您正苦於以下問題:Java Process.myTid方法的具體用法?Java Process.myTid怎麽用?Java Process.myTid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.Process
的用法示例。
在下文中一共展示了Process.myTid方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCanRecordEvent
import android.os.Process; //導入方法依賴的package包/類
@SmallTest
@Feature({"Android-AppBase"})
public void testCanRecordEvent() {
EarlyTraceEvent.enable();
long myThreadId = Process.myTid();
long beforeMs = SystemClock.elapsedRealtime();
EarlyTraceEvent.begin(EVENT_NAME);
EarlyTraceEvent.end(EVENT_NAME);
long afterMs = SystemClock.elapsedRealtime();
assertEquals(1, EarlyTraceEvent.sCompletedEvents.size());
assertTrue(EarlyTraceEvent.sPendingEvents.isEmpty());
EarlyTraceEvent.Event event = EarlyTraceEvent.sCompletedEvents.get(0);
assertEquals(EVENT_NAME, event.mName);
assertEquals(myThreadId, event.mThreadId);
assertTrue(beforeMs <= event.mBeginTimeMs && event.mBeginTimeMs <= afterMs);
assertTrue(event.mBeginTimeMs <= event.mEndTimeMs);
assertTrue(beforeMs <= event.mEndTimeMs && event.mEndTimeMs <= afterMs);
}
示例2: testThreadIdIsRecorded
import android.os.Process; //導入方法依賴的package包/類
@SmallTest
@Feature({"Android-AppBase"})
public void testThreadIdIsRecorded() throws Exception {
EarlyTraceEvent.enable();
final long[] threadId = {0};
Thread thread = new Thread() {
@Override
public void run() {
TraceEvent.begin(EVENT_NAME);
threadId[0] = Process.myTid();
TraceEvent.end(EVENT_NAME);
}
};
thread.start();
thread.join();
assertEquals(1, EarlyTraceEvent.sCompletedEvents.size());
EarlyTraceEvent.Event event = EarlyTraceEvent.sCompletedEvents.get(0);
assertEquals(threadId[0], event.mThreadId);
}
示例3: runOnMainThread
import android.os.Process; //導入方法依賴的package包/類
/** Runs the specified runnable immediately if called from the main thread, otherwise it is
* posted on the main thread handler. */
private void runOnMainThread(Runnable r) {
if (sWorkerThread.getThreadId() == Process.myTid()) {
// If we are on the worker thread, post onto the main handler
mHandler.post(r);
} else {
r.run();
}
}
示例4: runOnWorkerThread
import android.os.Process; //導入方法依賴的package包/類
/** Runs the specified runnable immediately if called from the worker thread, otherwise it is
* posted on the worker thread handler. */
private static void runOnWorkerThread(Runnable r) {
if (sWorkerThread.getThreadId() == Process.myTid()) {
r.run();
} else {
// If we are not on the worker thread, then post to the worker handler
sWorker.post(r);
}
}
示例5: run
import android.os.Process; //導入方法依賴的package包/類
@Override
public void run() {
mTid = Process.myTid();
Looper.prepare();
synchronized (this) {
mLooper = Looper.myLooper();
notifyAll();
}
Process.setThreadPriority(mPriority);
onLooperPrepared();
Looper.loop();
mTid = -1;
}
示例6: Event
import android.os.Process; //導入方法依賴的package包/類
Event(String name) {
mName = name;
mThreadId = Process.myTid();
mBeginTimeMs = SystemClock.elapsedRealtime();
}