0

So I have created a global class which extends globalsettings:

public class Global extends GlobalSettings {
private Thread thread = new Thread();

@Override
public void onStart(Application app) {
    ....
public void write(byte[] bytes) {
    ....

Which has a Thread in it as I am listening to a socket, so I need it up and running all the time. I tried to use Actors and had a class that extends UntypedActor but it seemed to be very hackish and I had to at the end of the call to the actor make it call itself.

I also need to write to the socket. which I have a method called write which writes to the socket. What I would like to do is from one of my methods call the global objects write method. Is there a way I can do this? Atm my Global object is not in a package. Do I need to put it into a package to get it to work?

4

1 回答 1

0

Ok so I solved my problem using the singleton pattern. Created an object called ThreadSingleton so that I could access it from anywhere.

For more information check out this link: http://en.wikipedia.org/wiki/Singleton_pattern

于 2012-06-20T23:51:46.400 回答