How to shut down the current thread having a state machine?

39 views
Skip to first unread message

Cheng

unread,
Feb 10, 2015, 1:14:24 PM2/10/15
to squirrel-st...@googlegroups.com
Hi,

I have the following main function:

public static void main(String[] args) {

StateMachine<FSM, FSMState, FSMEvent, String> fsm = createFSM();

fsm.fire(FSMEvent.QUESTION, "Why sky is blue?");

fsm.fire(FSMEvent.TERMINATE);

}

I also define an onEntry function for terminate event:

builder.onEntry(FSMState.TERMINATE).perform(

new AnonymousAction<FSM, FSMState, FSMEvent, String>() {

@Override
public void execute(FSMState from, FSMState to, FSMEvent event,
String context, FSM stateMachine) {

if (stateMachine.getStatus() != StateMachineStatus.TERMINATED) {
stateMachine.terminate(null);
} else {
System.out.println("Not terminated.");
}

}
});

When I ran and debugged the main function, I came to the line:

stateMachine.terminate(null);

It seems the line of code had been successfully executed. However, the main function is still hanging there.

How can I stop the main function from hanging?

Thanks.
Message has been deleted

He Henry

unread,
Feb 10, 2015, 9:36:18 PM2/10/15
to squirrel-st...@googlegroups.com
I don't think main thread will hang. You may need to check your implementation code or provide a runnable test case to reproduce your problem.

Here is my simple case. which will success.

在 2015年2月11日星期三 UTC+8上午2:14:24,Jonathan Zhou写道:
Reply all
Reply to author
Forward
0 new messages