This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 107424 - Easier way to write hints and cancelable tasks
Summary: Easier way to write hints and cancelable tasks
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-20 13:22 UTC by Jaroslav Tulach
Modified: 2016-05-25 06:08 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2007-06-20 13:22:58 UTC
Just a few minutes ago I needed to make my hint cancelable. What is the current advice?

public class Hint extends AbstractHint {
  private volatile boolean stop;

  public Hint run(CompilationInfo info) {
    stop = false;
    // ...
    if (stop) {
      return null;
    }
  }
  public void cancel() {
    stop = true;
  }

It is far too much code for my own taste and also the code is not really bulletproof. "stop" is a variable associated 
with one invocation not with the instance of the hint. If scheduler will suspend the run method before "stop = 
false;", other thread will call cancel, then the run method continues, the cancel never really happens.

I want easier way to handle cancel, without this concurrent subtlety: Why not have

public final boolean CompilationInfo.isCanceled();

method? The above code would than be just:

public class Hint extends AbstractHint {
  public Hint run(CompilationInfo info) {
    if (info.isCancelled()) {
      return null;
    }
  }
}

simpler, and without threading issues.
Comment 1 Tomas Zezula 2007-06-22 08:07:22 UTC
Needs huge API change but seems very elegant.
Comment 2 Tomas Zezula 2007-09-20 08:24:43 UTC
The nicest solution without a big change is to support both the current call of cancel () method and in addition to this
we may add the isCanceled() method to CompilationInfo as Jarda suggested.
Comment 3 Jiri Prox 2008-04-11 00:52:44 UTC
moving opened issues from TM <= 6.1 to TM=Dev