Is there any way to distinguish the main Thread from any Threads that it spawns?

前端 未结 3 878
予麋鹿
予麋鹿 2021-01-05 23:09

I know that the getName() function on the main thread will return the String main, but this can be changed with setName().

Is

3条回答
  •  我在风中等你
    2021-01-05 23:44

    From your question and your responses to comments I would suggest the following 2 approaches:

    1. Place all requests to an event queue and main thread will take the requests from request queue to call the method you are talking about. In this case there must be a contract that any other method wanting to access the method you are talking about can do it only via the event queue (same idea as EDT).

    2. Place an extra parameter in the method that you want to be called by main only to act as a token.Inside the method check if the token is correct (only main will have it/know it).If it is correct then proceed.Otherwise return false. Of course if you are allowed to make such a modification

提交回复
热议问题