Skip to content

Commit

Permalink
Make getAfterRun un-block avoid deadlock. (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbl-x authored and ujjboy committed Oct 17, 2018
1 parent 69334fa commit de44e2a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>bolt</artifactId>
<version>1.4.4</version>
<version>1.4.6</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/alipay/remoting/util/FutureTaskNotCompleted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.remoting.util;

/**
* Exception to represent the run method of a future task has not been finished.
*
* @author chengyi ([email protected]) 2018-10-18 02:06
*/
public class FutureTaskNotCompleted extends Exception {

private static final long serialVersionUID = -3635466558774380138L;

public FutureTaskNotCompleted() {

}

public FutureTaskNotCompleted(String message) {
super(message);
}

public FutureTaskNotCompleted(String message, Throwable cause) {
super(message, cause);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/alipay/remoting/util/FutureTaskUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static <T> T getFutureTaskResult(RunStateRecordedFutureTask<T> task, Logg
logger.error("Future task execute failed!", e);
} catch (FutureTaskNotRunYetException e) {
logger.error("Future task has not run yet!", e);
} catch (FutureTaskNotCompleted e) {
logger.error("Future task has not completed!", e);
}
}
return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ public void run() {
}

public V getAfterRun() throws InterruptedException, ExecutionException,
FutureTaskNotRunYetException {
FutureTaskNotRunYetException, FutureTaskNotCompleted {
if (!hasRun.get()) {
throw new FutureTaskNotRunYetException();
}

if (!isDone()) {
throw new FutureTaskNotCompleted();
}

return super.get();
}
}

0 comments on commit de44e2a

Please sign in to comment.