Access properties of the class passed to a thread

Hi You all,

I have the following code:

package com.services;

import java.util.*;

publicclass Timerimplements Runnable

{

//-

//CLASS OBJECTS

//-

privateint interval;

privatevolatileint clockFlag = 0;

//-

//CONSTRUCTOR

//-

public Timer()

{

}

//-

publicvoid stop()

{

this.interval = 0;

}

//-

publicvoid setInterval(int pInterval)

{

this.interval = pInterval + 100000000;

}

//-

publicvoid run()

{

while(this.interval != 0)

{

if(this.clockFlag == this.interval)

{

System.out.println("clockFlag");

this.clockFlag = 0;

}

this.clockFlag ++;

}

}

}

Timer objTimer =new Timer();

objTimer.setInterval(5);

Thread objThread =new Thread(objTimer);

objThread.start();

So if I want to use the run method of the Timer class what should I do?

Is there any method in the thread that alows me to call any method of the class passed to it?

Thanks,

MeTitus

[2548 byte] By [Me_Titusa] at [2007-10-3 8:42:06]
# 1
> So if I want to use the run method of the Timer> class what should I do?What do you mean? It's invoked by the thread that you start.Kaj
kajbja at 2007-7-15 3:50:29 > top of Java-index,Java Essentials,New To Java...
# 2
why are you still using runnable, just extend thread.
mkoryaka at 2007-7-15 3:50:30 > top of Java-index,Java Essentials,New To Java...
# 3
> why are you still using runnable, just extend thread.That's usually a bad design choice.Kaj
kajbja at 2007-7-15 3:50:30 > top of Java-index,Java Essentials,New To Java...
# 4
> That's usually a bad design choice.why?
mkoryaka at 2007-7-15 3:50:30 > top of Java-index,Java Essentials,New To Java...
# 5
> > That's usually a bad design choice.> > why?You should extend when you actually want to add some new functionality to a class, and the OP doesn't want to create a new type of thread. He just want to execute something in a new thread.Kaj
kajbja at 2007-7-15 3:50:30 > top of Java-index,Java Essentials,New To Java...
# 6
I got this problem solved...Thanks for all the replies ;)MeTitus
Me_Titusa at 2007-7-15 3:50:30 > top of Java-index,Java Essentials,New To Java...