# io.temporal.workflow.Workflow.newTimer(Duration.parse("PT5S")); raises exception

**URL:** <https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416>\
**Category:** Community Support\
**Created:** [January 31, 2021, 11:03pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416 "2021-01-31T23:03:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)\
**Post date:** [January 31, 2021, 11:03pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/1 "2021-01-31T23:03:30Z")

</div>

Hi,

When I am trying to create a timer, using the above syntax I am seeing the following exception, I am trying to create a Delay of 5 seconds without an await condition

“java.lang.IllegalStateException: Operation allowed only while eventLoop is running”

Any suggestions?

Thanks,

Kasi

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [January 31, 2021, 11:05pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/2 "2021-01-31T23:05:44Z")

</div>

In which method of the workflow are you calling `newTimer` function? Would you post the full stack trace of the exception?

---

<div class="post-metadata">

**Author:** ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)\
**Post date:** [January 31, 2021, 11:14pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/3 "2021-01-31T23:14:50Z")

</div>

in the starting workflow method, the first execution is introducing a timer delay,  
startWorkflow is a workflow method,

```java
public String startWorkflow(String data) {

    // will have to call other activities and stuff here
    System.out.println("Inside workflow");
    this.data = data;
    // we need a state machine which navigates thru the actions
    io.temporal.workflow.Workflow.newTimer(Duration.parse("PT5S"));

```

The exception thrown is part of java.lang.reflect.InvocationTargetException.

Thanks,

Kasi

---

<div class="post-metadata">

**Author:** ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)\
**Post date:** [January 31, 2021, 11:17pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/4 "2021-01-31T23:17:16Z")

</div>

Also, on a separate note, I used to be able to run the workflow in IDEA debugger, now I am seeing deadlock exception when running in debugger

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [January 31, 2021, 11:31pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/5 "2021-01-31T23:31:20Z")

</div>

I’ve just tested `Workflow.newTimer` and it worked fine for me. What is the stack trace of the `IllegalStateException`?

BTW. `Workflow.newTimer(Duration.parse("PT5S"))` returns a Promise that you are ignoring in the above sample, so your code is not going to block. Either call `get` on the returned promise or use `Workflow.sleep`.

> Also, on a separate note, I used to be able to run the workflow in IDEA debugger, now I am seeing deadlock exception when running in debugger

Add `TEMPORAL_DEBUG=true` environment variable to disable the deadlock detector.

---

<div class="post-metadata">

**Author:** ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)\
**Post date:** [February 1, 2021, 7:48pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/6 "2021-02-01T19:48:19Z")

</div>

Workflow.sleep throws the same exception.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [February 1, 2021, 7:54pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/7 "2021-02-01T19:54:17Z")

</div>

Then to help you we need at least the exception stack trace.

---

<div class="post-metadata">

**Author:** ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)\
**Post date:** [February 2, 2021, 4:13pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/8 "2021-02-02T16:13:03Z")

</div>

Hi Maxim,

Here is a snapshot of the error, can we webex for 10 minutes on this?

Thanks,

Kasi

 ![Screen Shot 2021-02-02 at 8.09.01 AM](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/1X/5a49158bfde081fd71974b9ed30387d272273607.png)

---

<div class="post-metadata">

**Author:** ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)\
**Post date:** [February 2, 2021, 4:39pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/9 "2021-02-02T16:39:56Z")

</div>

I made changes to existing HelloActivity from temporal samples project,

```auto
@Override
    public String getGreeting(String name) {
      // This is a blocking call that returns only after the activity has completed.
      Workflow.sleep(Duration.parse("PT5S"));
      Workflow.await(Duration.parse("PT5S"), () -> proceed);
      return activities.composeGreeting("Hello", name);
    }

```

running into same issue.

Thanks,

Kasi

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [February 2, 2021, 6:10pm UTC](https://community.temporal.io/t/io-temporal-workflow-workflow-newtimer-duration-parse-pt5s-raises-exception/1416/10 "2021-02-02T18:10:07Z")

</div>

I did the same change to the HelloAtivity and it [runs fine for me](https://github.com/temporalio/samples-java/compare/master...mfateev:event-loop-allowed?expand=1). Would you point me to the repository with the code that reproduces your issue?
