Skip to content

Commit

Permalink
#6560: fix codeCell example
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslawmalekcodete committed Jan 25, 2018
1 parent c994d35 commit e0d16c5
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static com.twosigma.beakerx.kernel.msg.JupyterMessages.EXECUTE_INPUT;

Expand All @@ -38,7 +39,7 @@
public class ExecuteRequestHandler extends KernelHandler<Message> {

private int executionCount;
private final Semaphore syncObject = new Semaphore(1, true);
private ExecutorService executorService = Executors.newFixedThreadPool(1);

public ExecuteRequestHandler(KernelFunctionality kernel) {
super(kernel);
Expand All @@ -47,15 +48,10 @@ public ExecuteRequestHandler(KernelFunctionality kernel) {

@Override
public void handle(Message message) {
try {
handleMsg(message);
} catch (Exception e) {
throw new RuntimeException(e);
}
executorService.submit(() -> handleMsg(message));
}

private void handleMsg(Message message) throws Exception {
syncObject.acquire();
private void handleMsg(Message message) {
kernel.sendBusyMessage(message);
executionCount += 1;
String codeString = takeCodeFrom(message);
Expand All @@ -67,7 +63,6 @@ private void handleMsg(Message message) throws Exception {

private void finishExecution(Message message) {
kernel.sendIdleMessage(message);
syncObject.release();
}

private String takeCodeFrom(Message message) {
Expand Down

0 comments on commit e0d16c5

Please sign in to comment.