Skip to content

Commit

Permalink
Use ThreadSafe Set instead Issue #1633
Browse files Browse the repository at this point in the history
  • Loading branch information
giangianoulas committed Apr 18, 2024
1 parent 5cc6ddb commit 46b6a89
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
Expand Up @@ -946,14 +946,12 @@ private static class OdaQueryCanceller implements ICancellable {
private StopSign stop;
private DataException exception;
private DataSourceQuery dsQuery;
private final String id;

OdaQueryCanceller(PreparedStatement statement, DataSource dataSource, StopSign stop, DataSourceQuery dsQuery) {
this.statement = statement;
this.stop = stop;
this.dataSource = dataSource;
this.dsQuery = dsQuery;
this.id = java.util.UUID.randomUUID().toString();
}

/**
Expand Down Expand Up @@ -1004,11 +1002,6 @@ public void cancel() {
public boolean doCancel() {
return this.stop.isStopped();
}

@Override
public String getId() {
return this.id;
}
}

/**
Expand Down
Expand Up @@ -14,19 +14,17 @@
*******************************************************************************/
package org.eclipse.birt.data.engine.impl;

import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;

/**
*
*/

public class CancelManager extends TimerTask {
//
private Map<String, ICancellable> cancellableMap = new HashMap<>();
private final Set<ICancellable> cancellables = ConcurrentHashMap.newKeySet();

/**
* Constructor
Expand All @@ -39,19 +37,15 @@ public CancelManager() {
* @param cancellable
*/
public void register(ICancellable cancellable) {
synchronized (cancellableMap) {
cancellableMap.put(cancellable.getId(), cancellable);
}
cancellables.add(cancellable);
}

/**
*
* @param cancellable
*/
public void deregister(ICancellable cancellable) {
synchronized (cancellableMap) {
cancellableMap.remove(cancellable.getId());
}
cancellables.remove(cancellable);
}

/*
Expand All @@ -65,11 +59,7 @@ public void run() {
}

public void doCancel() {
List<ICancellable> cancellableCollection = null;
synchronized (cancellableMap) {
cancellableCollection = new ArrayList<>(cancellableMap.values());
}
for (ICancellable cancellable : cancellableCollection) {
for (ICancellable cancellable : cancellables.toArray(ICancellable[]::new)) {
if (cancellable.doCancel()) {
cancellable.cancel();
}
Expand Down
Expand Up @@ -26,6 +26,4 @@ public interface ICancellable {
void cancel();

DataException collectException();

String getId();
}

0 comments on commit 46b6a89

Please sign in to comment.