Newsgroup: it.comp.java
Titolo: Thread.interrupt()

Salve a tutti,
vorrei avere delle delucidazioni sul funzionamento del metodo
Thread.interrupt()
a me sembra analogo a Thread.stop(). Che differenza c'e'?
Grazie a tutti
Fabrizio

 ha scritto nel messaggio
news:9a1lbe$2u7$1...@ftp-news.csita.unige.it...


stop
public final void stop()
  Deprecated. This method is inherently unsafe. Stopping a thread with
Thread.stop causes it to unlock all of the monitors that it has locked (as a
natural consequence of the unchecked ThreadDeath exception propagating up
the stack). If any of the objects previously protected by these monitors
were in an inconsistent state, the damaged objects become visible to other
threads, potentially resulting in arbitrary behavior. Many uses of stop
should be replaced by code that simply modifies some variable to indicate
that the target thread should stop running. The target thread should check
this variable regularly, and return from its run method in an orderly
fashion if the variable indicates that it is to stop running. If the target
thread waits for long periods (on a condition variable, for example), the
interrupt method should be used to interrupt the wait. For more information,
see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
  Forces the thread to stop executing.
  If there is a security manager installed, its checkAccess method is called
with this as its argument. This may result in a SecurityException being
raised (in the current thread).
  If this thread is different from the current thread (that is, the current
thread is trying to stop a thread other than itself), the security manager's
checkPermission method (with a RuntimePermission("stopThread") argument) is
called in addition. Again, this may result in throwing a SecurityException
(in the current thread).
  The thread represented by this thread is forced to stop whatever it is
doing abnormally and to throw a newly created ThreadDeath object as an
exception.
  It is permitted to stop a thread that has not yet been started. If the
thread is eventually started, it immediately terminates.
  An application should not normally try to catch ThreadDeath unless it must
do some extraordinary cleanup operation (note that the throwing of
ThreadDeath causes finally clauses of try statements to be executed before
the thread officially dies). If a catch clause catches a ThreadDeath object,
it is important to rethrow the object so that the thread actually dies.
  The top-level error handler that reacts to otherwise uncaught exceptions
does not print out a message or otherwise notify the application if the
uncaught exception is an instance of ThreadDeath.
    Throws:
    SecurityException - if the current thread cannot modify this thread.
    See Also:
    interrupt(), checkAccess(), run(), start(), ThreadDeath,
ThreadGroup.uncaughtException(java.lang.Thread, java.lang.Throwable),
SecurityManager.checkAccess(Thread),
SecurityManager.checkPermission(java.security.Permission)
----------------------------------------------------------------------------
----
interrupt
public void interrupt()
  Interrupts this thread.
  First the checkAccess method of this thread is called with no arguments.
This may result in throwing a SecurityException.
    Throws:
    SecurityException - if the current thread cannot modify this thread.