本文整理汇总了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();
}