Should Java Thread IDs always start at 0?

I am working on a mutual exclusion assignment, but when I started I noticed my application's thread ID's start at 9. It doesn't change when I compile and execute it again. Is there some problem I'm missing, or can Java Thread IDs start at an arbitrary number? [This question][1] is related. ---------- For those interested, here is a class from Herlihy & Shavit's "The Art of Multiprocessor Programming" for numbering threads: public class ThreadID { private static volatile int nextID = 0; private static class ThreadLocalID extends ThreadLocal { protected synchronized Integer initialValue() { return nextID++; } } private static ThreadLocalID threadID = new ThreadLocalID(); public static int get() { return threadID.get(); } public static void set(int index) { threadID.set(index); } } You can then call ThreadID.get(); which will automatically increment numbers and always start at 1. [1]: https://stackoverflow.com/questions/591627/thread-getid-global-uniqueness-question

以上就是Should Java Thread IDs always start at 0?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏