Java: Thread.currentThread().sleep(x) vs. Thread.sleep(x)

后端 未结 4 738
清歌不尽
清歌不尽 2020-12-04 13:33

I have this in my code

Thread.currentThread().sleep(x);

Eclipse tells me to use the static

Thread.sleep(x); 
4条回答
  •  自闭症患者
    2020-12-04 13:49

    Thread.currentThread().sleep(x); or the way Eclipse says so Thread.sleep(x); static context is required if it is in the need, so we hold on for slight delay with this sleep.

    Static paradigm set by one object, only affects that particular object heap print life cycle, again considering the overall Object Life Cycle static is not that bothersome, if required it can be used to ease the coding, but to be done carefully as static foot-print is referred by Class (for example:- Class.forName(pkg.className)) as like by name and not by any object which is run-time single print copy of Class in HEAP memory.

    Again usage of object also has pros & cons by Weak, Phantom, Strong kind of references....,

    Code is Convoluted by Nature. It is just the way how we do in order to make it work & functional.

提交回复
热议问题