0

This is a school assignment I have been working on. I've been back and forth with my tutor and he's been helping me with this but there's something I'm obviously missing here. The program in question takes an argument, "-f filename.txt" and in that filename are a list of things like this

FansOn, 2000
FansOff, 4000
Bell, 2000,5

The program does takes those names and creates classes using reflection and then calls the action() method of the generated classes (FansOn, etc.). It creates a thread for each class and then starts the thread, which generates a message like "Fan is on". On two of the events, PowerOut and WindowMalfunction, it throws a custom exception ControllerException which then needs to grab an object called GreenhouseControls and serialize it to a file called dump.out for later examination. The problem I'm having is being able to call my ghcSuspend() method which should suspend all events immediately after the exception call. In fact, at this point my program just generates massive stack overflow issues. I don't know if I should post my entire code here because I obviously don't want someone else taking my course to just get handed the bulk of code so I don't know what I should post to make you guys understand my issue.

So in my main() method, i create a GreenhouseControls object called gc. GreenhouseControls is the name of the main class file. Eventually, I need this gc object in my custom exception, which is defined and caught in my events.class file

4

1 回答 1

0

我想出了这个。因为我的对象是在 run 方法中创建的,所以我基本上必须将它传递给一个接一个地调用的每个方法,直到它到达我需要处理它的最终方法。我错过了一些基本的 OO 概念,这些概念最终创建了一个无限循环,溢出了我的堆栈。所以我们现在都很好。

于 2011-12-09T03:48:21.743 回答