Why does it happen that the stack trace printed for the following Java program is not displayed in a proper order on the console screen? It gets mixed up with other messages on the screen.
Is there any parallelism involved which causes it?
Java program:
package evm;
public class Client {
public static void main(String[] args) {
EVM evm = new EVM();
try {
evm.setCandidates(90); /**An Exception thrown here**/
} catch (CandidatesOutOfLimitsException e) {
e.printStackTrace();
//System.out.print(e.getMessage());
}
try {
evm.voteForCandidate(43); /**An Exception thrown here**/
} catch (BallotUnitOffException e1) {
e1.printStackTrace();
//System.out.print(e1.getMessage());
}
evm.pressBallotButton();
System.out.println(evm); //other messages
evm.switchOn();
System.out.println(evm); //other messages
try {
evm.voteForCandidate(43); /**An Exception thrown here**/
} catch (BallotUnitOffException e) {
e.printStackTrace();
//System.out.print(e.getMessage());
}
}
}
I have commented against the lines which throw an Exception.
run 1:
evm.CandidatesOutOfLimitsException: Number of Candidates cannot exceed 64
at evm.EVM.setCandidates(EVM.java:41)
at evm.Client.main(Client.java:9)
evm.BallotUnitOffException: Ballot Unit is not On
at evm.BallotUnit.pressCandidateButton(BallotUnit.java:38)
at evm.EVM.voteForCandidate(EVM.java:59)
at evm.Client.main(Client.java:16)
evm.BallotUnitOffException: Ballot Unit is not On
at evm.BallotUnit.pressCandidateButton(BallotUnit.java:38)
at evm.EVM.voteForCandidate(EVM.java:59)
at evm.Client.main(Client.java:28)
Control Unit State: evm.Off@42a57993
On Lamp: evm.Off@15db9742Ballot Unit: Ready Lamp: evm.Off@6d06d69c
Slide Switch:evm.SlideSwitchOne@7852e922
Ballot Unit: Ready Lamp: evm.Off@4e25154f
Slide Switch:evm.SlideSwitchTwo@70dea4e
Ballot Unit: Ready Lamp: evm.Off@5c647e05
Slide Switch:evm.SlideSwitchThree@33909752
Ballot Unit: Ready Lamp: evm.Off@55f96302
Slide Switch:evm.SlideSwitchFour@3d4eac69
Control Unit State: evm.On@28d93b30
On Lamp: evm.On@75b84c92Ballot Unit: Ready Lamp: evm.On@6bc7c054
Slide Switch:evm.SlideSwitchOne@7852e922
Ballot Unit: Ready Lamp: evm.On@232204a1
Slide Switch:evm.SlideSwitchTwo@70dea4e
Ballot Unit: Ready Lamp: evm.On@4aa298b7
Slide Switch:evm.SlideSwitchThree@33909752
Ballot Unit: Ready Lamp: evm.On@7d4991ad
Slide Switch:evm.SlideSwitchFour@3d4eac69
run 2:
evm.CandidatesOutOfLimitsException: Number of Candidates cannot exceed 64
at evm.EVM.setCandidates(EVM.java:41)
at evm.Client.main(Client.java:9)
evm.BallotUnitOffException: Ballot Unit is not On
at evm.BallotUnit.pressCandidateButton(BallotUnit.java:38)
at evm.EVM.voteForCandidate(EVM.java:59)
at evm.Client.main(Client.java:16)
Control Unit State: evm.Off@42a57993
On Lamp: evm.Off@15db9742Ballot Unit: Ready Lamp: evm.Off@6d06d69c
Slide Switch:evm.SlideSwitchOne@7852e922
Ballot Unit: Ready Lamp: evm.Off@4e25154f
Slide Switch:evm.SlideSwitchTwo@70dea4e
Ballot Unit: Ready Lamp: evm.Off@5c647e05
Slide Switch:evm.SlideSwitchThree@33909752
Ballot Unit: Ready Lamp: evm.Off@55f96302
Slide Switch:evm.SlideSwitchFour@3d4eac69
Control Unit State: evm.On@28d93b30
On Lamp: evm.On@75b84c92Ballot Unit: Ready Lamp: evm.On@6bc7c054
Slide Switch:evm.SlideSwitchOne@7852e922
Ballot Unit: Ready Lamp: evm.On@232204a1
Slide Switch:evm.SlideSwitchTwo@70dea4e
Ballot Unit: Ready Lamp: evm.On@4aa298b7
Slide Switch:evm.SlideSwitchThree@33909752
Ballot Unit: Ready Lamp: evm.On@7d4991ad
Slide Switch:evm.SlideSwitchFour@3d4eac69
evm.BallotUnitOffException: Ballot Unit is not On
at evm.BallotUnit.pressCandidateButton(BallotUnit.java:38)
at evm.EVM.voteForCandidate(EVM.java:59)
at evm.Client.main(Client.java:28)
Similarly I get some other patterns every time I run it. Anybody explain this behavior.
I am using
Eclipse Java EE IDE for Web Developers.
Version: Luna Release (4.4.0)
Build id: 20140612-0600
I apologize for lengthy question
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…