0

As per my company rule I can not use stop() of thread

For that I want something like when I use stop(), eclipse should shows error/warning It is difficult to achieve by using checkstyle and PMD.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 5
    Thread's `stop()` method is deprecated and Eclipse already shows the warning for deprecated methods, what specific thing do you want? – vishal_aim May 13 '13 at 05:35

2 Answers2

1

You will probably have to consider using FindBugs instead of Checkstyle or PMD, because you need to know the runtime type of a variable in order to see whether it is an instance of Thread or not.

AFAIK, none of the tools has a built-in detector/check for your Thread.stop() rule, so you will have to write a custom Findbugs detector.

A simpler way of achieving this (but not suitable for an enterprise development environment) would be to simply check for occurrences of Thread.currentThread().stop() and the like using Checkstyle and a regular expression. Let me know in the comments if you would like an example for that.

barfuin
  • 16,865
  • 10
  • 85
  • 132
0

Well you cannot over ride the stop() or other method inside java.* classes. You can use code scanners to search for stop() being called on instances of threads.

You could extend thread and then use that (in your class stop method can do nothing or throw and exception) but again you would have to mandate that every use that new class.

But why do they want you to do that? if your using multi threading use pools (and only create Runnable classes) or if you MUST use threads then have other methods to stop the processing of them (like a flag and checking the flag during processing, and having a setter to set the falg from other thread)

Sukhdev
  • 36
  • 4