Nemam destruktor. Ako zastavim Timer()?

Martin Kuba makub na ics.muni.cz
Čtvrtek Únor 19 12:46:23 CET 2009


Nahlédnutím do javadocu na
http://java.sun.com/javase/6/docs/api/java/util/Timer.html
jsem se dočetl, že

By default, the task execution thread does not run as a daemon thread,
so it is capable of keeping an application from terminating.

čili řešením je použít správný konstruktor a nastavit Timeru, aby
používal daemon thread, tj.

Timer timer = new Timer(true);

Makub

Dusan Zatkovsky napsal(a):
> MyClasSlave::flush()
> 
> ... a main samozrejme neskonci a apkilacia zostane vysiet.
> 
> 
> V C++, alebo inom jazyku nepostradajucom destruktory, by som vyrobil nieco 
> ako:
> 
> void MyClassSlave::~MyClassSlave() {
> 	this.timer.cancel();
> }
> 
> ... a bolo by po probleme. Ako ale pre boha vyriesim tento problem v Jave bez 
> toho, aby som z main() hierarchicky volal nejaku nahrazku destruktoru, 
> povedzme stop()?
> 
> Diky za nakop.
> 
> 


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Supercomputing Center Brno             Martin Kuba
Institute of Computer Science    email: makub na ics.muni.cz
Masaryk University             http://www.ics.muni.cz/~makub/
Botanicka 68a, 60200 Brno, CZ     mobil: +420-603-533775
--------------------------------------------------------------

------------- další část ---------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3254 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://amaio.cz/pipermail/konference/attachments/20090219/cf52af2c/attachment.bin>


Další informace o konferenci Konference