Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » try to kill thread in dispose method
try to kill thread in dispose method [message #282003] Wed, 02 March 2005 12:08 Go to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------080009090705030304010905
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi,
I have an org.eclipse.ui.part.ViewPart implemented.
In the method createPartControl(Composite) I start an nested thread
which updates a label in the view. (Display.getDefault().asyncExec)
That work fine.
If I close the view I try to destroy the tread in the method dispose.

But then the log runs full:

Unhandled event loop exception
Reason:
Widget is disposed

mfg Thomas Richter

--
Thomas Richter 'Codito ergo sum' Diplominformatiker Softwareentwickler
tr@ariva.de http://www.ariva.de
+(49) 0431/97108-27
B
Re: try to kill thread in dispose method [message #282052 is a reply to message #282003] Thu, 03 March 2005 14:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

probably it has nothing to do with destroy, and the thread is still
running after the display has been disposed. It would seem that you
need to shut the thread down earlier. Perhaps add a partlistener to the
part and use the partlistener's events instead.

CL


Thomas Richter wrote:
> Hi,
> I have an org.eclipse.ui.part.ViewPart implemented.
> In the method createPartControl(Composite) I start an nested thread
> which updates a label in the view. (Display.getDefault().asyncExec)
> That work fine.
> If I close the view I try to destroy the tread in the method dispose.
>
> But then the log runs full:
>
> Unhandled event loop exception
> Reason:
> Widget is disposed
>
> mfg Thomas Richter
>
>
> ------------------------------------------------------------ ------------
>
> /* Created on 21.02.2005 */
>
> package de.adblue.clock.views;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
>
> import org.eclipse.ui.part.ViewPart;
>
> import java.text.SimpleDateFormat;
>
> import java.util.Date;
>
> /**
> * @author richter
> */
> public class SWTClock extends ViewPart {
>
> private Label _lbl;
>
> private Thread t;
>
> private Composite c = null;
>
> public SWTClock() {
> super();
> }
>
> public void dispose() {
> super.dispose();
> t.destroy();
> }
>
> public void createPartControl(Composite parent) {
> c = new Composite(parent, SWT.CENTER);
> _lbl = new Label(parent, SWT.CENTER);
> _lbl.setToolTipText("das aktuelle Datum");
> updateLabel(new Date());
> t = new Thread(new ClockUpdater()); //.start();
> t.start();
> }
>
> private void updateLabel(Date date) {
> _lbl.setText(new SimpleDateFormat("HH:mm:ss").format(date));
> }
>
> public void setFocus() {
> c.setFocus();
> }
>
> private final class ClockUpdater implements Runnable {
>
> public void run() {
> while (true) {
> try {
> Thread.sleep(1000);
> }
> catch (Exception e) {
> System.err.println(e);
> }
> Display.getDefault().asyncExec(new MyRunnable2());
> }
> }
>
> private final class MyRunnable2 implements Runnable {
>
> public void run() {
> updateLabel(new Date());
> }
> }
> }
> }
Re: try to kill thread in dispose method [message #282053 is a reply to message #282003] Thu, 03 March 2005 14:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

perhaps call destroy before you call super.dispose();

CL

Thomas Richter wrote:
> Hi,
> I have an org.eclipse.ui.part.ViewPart implemented.
> In the method createPartControl(Composite) I start an nested thread
> which updates a label in the view. (Display.getDefault().asyncExec)
> That work fine.
> If I close the view I try to destroy the tread in the method dispose.
>
> But then the log runs full:
>
> Unhandled event loop exception
> Reason:
> Widget is disposed
>
> mfg Thomas Richter
>
>
> ------------------------------------------------------------ ------------
>
> /* Created on 21.02.2005 */
>
> package de.adblue.clock.views;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
>
> import org.eclipse.ui.part.ViewPart;
>
> import java.text.SimpleDateFormat;
>
> import java.util.Date;
>
> /**
> * @author richter
> */
> public class SWTClock extends ViewPart {
>
> private Label _lbl;
>
> private Thread t;
>
> private Composite c = null;
>
> public SWTClock() {
> super();
> }
>
> public void dispose() {
> super.dispose();
> t.destroy();
> }
>
> public void createPartControl(Composite parent) {
> c = new Composite(parent, SWT.CENTER);
> _lbl = new Label(parent, SWT.CENTER);
> _lbl.setToolTipText("das aktuelle Datum");
> updateLabel(new Date());
> t = new Thread(new ClockUpdater()); //.start();
> t.start();
> }
>
> private void updateLabel(Date date) {
> _lbl.setText(new SimpleDateFormat("HH:mm:ss").format(date));
> }
>
> public void setFocus() {
> c.setFocus();
> }
>
> private final class ClockUpdater implements Runnable {
>
> public void run() {
> while (true) {
> try {
> Thread.sleep(1000);
> }
> catch (Exception e) {
> System.err.println(e);
> }
> Display.getDefault().asyncExec(new MyRunnable2());
> }
> }
>
> private final class MyRunnable2 implements Runnable {
>
> public void run() {
> updateLabel(new Date());
> }
> }
> }
> }
Re: try to kill thread in dispose method [message #282056 is a reply to message #282003] Thu, 03 March 2005 15:29 Go to previous message
Eclipse UserFriend
Originally posted by: chaves.inf.no.ufsc.spam.br

Thread.destroy() does not do anything...

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.htm l#destroy()

On how to allow a thread to stop another thread see:

http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimiti veDeprecation.html

HTH,

Rafael

Thomas Richter wrote:
> Hi,
> I have an org.eclipse.ui.part.ViewPart implemented.
> In the method createPartControl(Composite) I start an nested thread
> which updates a label in the view. (Display.getDefault().asyncExec)
> That work fine.
> If I close the view I try to destroy the tread in the method dispose.
>
> But then the log runs full:
>
> Unhandled event loop exception
> Reason:
> Widget is disposed
>
> mfg Thomas Richter
>
>
> ------------------------------------------------------------ ------------
>
> /* Created on 21.02.2005 */
>
> package de.adblue.clock.views;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
>
> import org.eclipse.ui.part.ViewPart;
>
> import java.text.SimpleDateFormat;
>
> import java.util.Date;
>
> /**
> * @author richter
> */
> public class SWTClock extends ViewPart {
>
> private Label _lbl;
>
> private Thread t;
>
> private Composite c = null;
>
> public SWTClock() {
> super();
> }
>
> public void dispose() {
> super.dispose();
> t.destroy();
> }
>
> public void createPartControl(Composite parent) {
> c = new Composite(parent, SWT.CENTER);
> _lbl = new Label(parent, SWT.CENTER);
> _lbl.setToolTipText("das aktuelle Datum");
> updateLabel(new Date());
> t = new Thread(new ClockUpdater()); //.start();
> t.start();
> }
>
> private void updateLabel(Date date) {
> _lbl.setText(new SimpleDateFormat("HH:mm:ss").format(date));
> }
>
> public void setFocus() {
> c.setFocus();
> }
>
> private final class ClockUpdater implements Runnable {
>
> public void run() {
> while (true) {
> try {
> Thread.sleep(1000);
> }
> catch (Exception e) {
> System.err.println(e);
> }
> Display.getDefault().asyncExec(new MyRunnable2());
> }
> }
>
> private final class MyRunnable2 implements Runnable {
>
> public void run() {
> updateLabel(new Date());
> }
> }
> }
> }
Previous Topic:not able to load an external jar
Next Topic:org.eclipse.ui.newWizards extension point question on the 'Category'
Goto Forum:
  


Current Time: Fri Aug 22 00:37:33 EDT 2025

Powered by FUDForum. Page generated in 0.09543 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top