1

My application has some Threads that are initiated in Main Class.

And I want to use MVC in this Swing Application.

The Main class waits a socket connection from some client, then when the client is connected I create a telnet object from a Telnet class that I create. And this class has all the shared resources that the threads will use.

After this I start my threads, passing the telnet object as a parameter, so it will be used to syncrhonize the threads.

There are five threads in my application: Client, Management, Server, Node and Agent.

Each one has a specific function.

So this is my scenario.

I want to use MVC in my application to organize these threads more properly, and make the application more easy to maintain.

I've already used MVC in Swing application, but without threads.

3
  • 4
    Your question seems a bit broad to me, and you may wish to flesh out this question a bit more, to provide more meat for us to work with. The greater the relevant detail that you can provide, the better the example code that you can show us, the better we'll be able to help you. Commented Jul 11, 2014 at 13:56
  • 3
    For instance, what do you mean by "call my Threads"? Do you mean to initiate a new Thread? Do you mean to communicate with objects whose methods are being run in a background thread? Where does your model fit in all of this? And where exactly are you stuck? Commented Jul 11, 2014 at 14:01
  • Look the update please Commented Jul 11, 2014 at 14:07

1 Answer 1

3

Perhaps it's me, but your question still seems quite broad to me, and so I can only offer broad suggestions.

  • Key in my mind will be how will objects communicate with each other, and I think that this is more important to me than how "Threads" communicate.
  • Best I think is to use an observer pattern.
  • If your Threads are created using a SwingWorker, then you have two main ways to communicate back to your Swing application:
    • You can use the publish/process method pair, where you pass an object into a publish method call, and then make Swing calls, perhaps to change your model's state via the process method. I don't like this approach as well, since coupling is increased, as the SwingWorker must know about the structure and behavior of the view or control code that it calls inside of the process method.
    • Or you can use the SwingWorker's innate SwingPropertyChangeSupport abilities to allow listeners (here the controller) to be notified of changes in the state of the worker. Then the controller can extract information that has changed and pass it to the model. I tend to favor this approach since for me, it is much easier to loosen coupling.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.