在 Java/Android 中,有没有办法检查当前执行的代码行是否在后台线程上执行?
我有一个我正在想象的小程序,它终于达到了完整的意大利面阶段……这是故意的,你看,因为这样……如果竞争对手拿到代码,他们“打开引擎盖,”看着它超过 20 秒后,他们的头发会着火,他们会尖叫着逃跑......但现在连我也感到困惑,我需要以某种方式检查这种情况。
附件-A:
// can be called from 1,067 places... some of which are background threads.
public void startDoingAFunDance(String caller, int wobbleIntensity, int spineAngle, int feetSeparationInInches) {
if (!validCallersForFunDance.contains(caller)) {
Log.i("XXX", "Caller not allowed.");
return;
}
boolean wasCalledFromBackgroundThread = // ? < what to put here > ?
Log.i("XXX", "Was startDoingAFunDance() called from a background thread? And the answer is: " + wasCalledFromBackgroundThread);
// classified
}
慕妹3242003
相关分类