Combine Multi-Threading Application with Event-Driven Model

PART 1: BACKGROUND

In the past couple of months, I dedicated on developing a multi-threading application, which heavily relied on thread cooperation. For a significant period the spaghetti code is totally embarrassing, the thread control code and the business code, the log code mixed all together, a big mess in fact.

As the business part became more and more complicated, I had to make some change. How to separate the thread cooperation part and the business part? My best shot is applying event-driven model, say, for example, one thread notified in a particular loop, I see an event triggered, and we can define the event handler/listener in other classes.

PART 2: EVENT-DRIVEN MODEL

At first, observer pattern came into my mind. Apart from that, there are some excellent examples for event-driven application, like Hibernate's core implementation, and Servlet Specification. Do some homework over them.

你可能感兴趣的:(Combine Multi-Threading Application with Event-Driven Model)