I recently came across AWT sources EventQueuewhere I saw this piece of code:
EventQueue
final boolean isDispatchThreadImpl() { EventQueue eq = this; pushPopLock.lock(); try { EventQueue next = eq.nextQueue; while (next != null) { eq = next; next = eq.nextQueue; } if (eq.fwDispatcher != null) { return eq.fwDispatcher.isDispatchThread(); } return (Thread.currentThread() == eq.dispatchThread); } finally { pushPopLock.unlock(); } }
What really struggles with me is that stream objects are compared using ==. So far I have been doing this with help equals(Object). I have already addressed this question , but the two answers are actually not what I am looking for.
==
equals(Object)
Is it possible that two different instances refer to the same native thread? How should I compare stream objects for equality?
Is it possible that two different instances refer to the same native thread?
No.
According to Threadjavadoc:
Thread
- .
Thread :
start() Thread , . ; .. start() . ( .)
start()
start() , run() , Thread . ( .)
run()
run() Thread , . ( , , .)
Thread ; .
?
== - .
equals(Object) , Thread Object, , ==.
Object
.
, equals. Thread javadoc ( ) , equals == . , , Thread. , " ", . ( , "" ... , .)
equals
, . , == .
: , , .
, : , . , " " . , , "" () , .
, equals(Object) , , , . , , ""; , , , 99% , / .
, TJ Crowder: Thread.equals(Object) Object.equals(Object), ... . , . , Thread .
Thread.equals(Object)
Object.equals(Object)
, : Java- .
JSL-17:
, ,
, , . , .
equals(Object) . Thread == equals(Object).
Thread.equals(Object), java.lang.Object:
java.lang.Object
public boolean equals(Object obj) { return (this == obj); }
Source: https://habr.com/ru/post/1657355/More articles:Bind Intel XDK stand, even before redirection - javascriptJavaScript filtering by comparing two arrays - javascriptPushing a local branch to a remote branch - gitpython - gitXcode 7 - the same file opened in different tabs - fileError: The parallel step can only be used as the only top-level step - jenkinsJavascript method and local variable - javascriptSynchronized () block does not work as expected - javaHow to define design rules for Java classes? - javaShift key in browser insert event not supported? - javascriptИзмените синий перегной на входе (флажки) (бутстрап 4) - htmlAll Articles