Jump to content
  • 0

Compare Threads


Question

Posted

Lets say i have got such code inside class:

ScheduledFuture<?> thread;
private void startThread()
{
thread = ThreadPoolManager.getInstance().schedule(new TestThread(), 5000);
}

private class TestThread implements Runnable
{
@Override
public void run()
{
System.out.println(thread.equals(TestThread.this));
}
}

 

It prints false to console, any idea to check if saved in var thread is running thread?

13 answers to this question

Recommended Posts

  • 0
Posted

class nameclass implements Runnable 
{
namethread runner;
public RunnableThread(String threadName) {
	namethread = new Thread(this, threadName); 
	System.out.println(runner.getName());
	namethread.start(); 
}
public void run() {
	System.out.println(Thread.currentThread());
}
}

 

dunno if you wanna smth like this,

didn't used eclipse,i may have miss some tokens,dunno ;p

  • 0
Posted

:O thx a lot for an idea, final version will be:

Thread thread;
private void startThread()
{
ThreadPoolManager.getInstance().schedule(new TestThread(), 5000);
}

private class TestThread implements Runnable
{
Thread current;
private TestThred()
{
current = Thread.currentThread();
thread = current;
}
@Override
public void run()
{
System.out.println(thread.equals(current));
}
}

thx, i think its the best way to achieve that :)

  • 0
Posted

the problem in this code, is that thread nor the current variable cannot be stopped at all, i tried interrupt() and also stop() methods but finally System.out.println(thread.equals(current)); is done every time.

I tried also to make new method in TestThread class to set "finished" boolean as false and later put IF before print but i cannot cast TestThread into a Thread class :/

  • 0
Posted

To stop a Thread from ThreadPoolManager, it's .cancel(boolean) *AND* put the task to null, aka "_task = null;".

cancel method is inside ScheduledFuture or Future classes, not Thread :)

  • 0
Posted

cancel method is inside ScheduledFuture or Future classes, not Thread :)

I never said that, I just said the correct mean to stop a thread, as you seem to get issues as you do weird things about comparing threads which is a nonsense until you got an issue with threads which made me thought about saying to you the correct way to stop a thread.

 

See, the snake eats his tail.

  • 0
Posted

I resolved it in different way. When player is cancelling other player buffs, new Thread starts and it is added to a List of Threads. When Thread is finished, i am deleting it from list by checking Thread.currentThread() as before. I need the list because sometimes i want to cancel all Threads and clear the list. But i thought that i will not cancel them, but when thread starts to work(after sleeping :P) he will just check at the beggining, if its on the list. Thx for help :)

  • 0
Posted

guys dont laugh at me..but i have to make a suggetion.what if you type break; under

System.out.println(thread.equals(TestThread.this));

u will have error :P break can be used only inside switches and loops and anyway it wouldnt change anything :)

  • 0
Posted

u will have error :P break can be used only inside switches and loops and anyway it wouldnt change anything :)

your right bro sorry im just reading e-books....so i just read it bellow :P

  • 0
Posted

I resolved it in different way. When player is cancelling other player buffs, new Thread starts and it is added to a List of Threads. When Thread is finished, i am deleting it from list by checking Thread.currentThread() as before. I need the list because sometimes i want to cancel all Threads and clear the list. But i thought that i will not cancel them, but when thread starts to work(after sleeping :P) he will just check at the beggining, if its on the list. Thx for help :)

A list of threads ? Gods. Help. Him.

 

Take a look on AttackStanceTaskManager... A unique thread with a unique map. On aCis, I did PvPFlag, Watertask and TakeBreak tasks looking as AttackStance.

  • 0
Posted

A list of threads ? Gods. Help. Him.

 

Take a look on AttackStanceTaskManager... A unique thread with a unique map. On aCis, I did PvPFlag, Watertask and TakeBreak tasks looking as AttackStance.

thats good idea, dunno why i didnt thought about that before, thx. Locking it :)

Guest
This topic is now closed to further replies.


  • Posts

    • L2 HARMONY - BANNERS & ICONS       L2 COLD - NPC ANIMATED BANNER
    • LA ERA DE EINHASAD - Lineage 2 en Castellano Lineage II Crónica 4: Vástagos del Destino x5 - Main Class - Full Craft ───────────────────────────── La diosa Einhasad ha despertado... Una nueva era comienza para los verdaderos aventureros. Un mundo completamente traducido al español, fiel al Lineage II original, creado para una comunidad hispanohablante unida por la nostalgia y la pasión. ───────────────────────────── APERTURA OFICIAL: 14 de NOVIEMBRE - 20:00hs (GMT-3) ───────────────────────────── INFORMACIÓN PRINCIPAL Rates: x5 Tipo: Main Class Sistema: Full Craft Idioma: 100% Español (traducción completa del juego) Comunidad hispanohablante Balance original con mínimas modificaciones Buffer Offline, los jugadores pueden crear sus tiendas de buffs Progresión de crónicas cada 4 meses aprox. Economía estable - Sin Pay to Win - No venta de items/adena por donación Comunidad de 1.000 personas Anterior versión x1 duro casi 3 años con 952 IPs distintas de pico ───────────────────────────── CARACTERÍSTICAS DESTACADAS Experiencia fiel al Lineage II clásico, sin alteraciones invasivas Interfaz, diálogos y objetos completamente en español Ventana de comunidad con servicios personalizados y comercio por Monedas de Oro Olimpiadas, Épicos y Asedios originales Recompensas por votación, Eventos TVT con 3 arenas diferentes. Participan todos sin importar el nivel, pero dentro de la arena solo se atacan por rango cercano Soporte activo y presencia constante del administrador Tickets de soporte con atención rápida en Discord ante cualquier problema ───────────────────────────── ENLACES OFICIALES Website: La Era de Einhasad Discord: https://discord.com/invite/A6PtCCN2SF ───────────────────────────── Una comunidad unida por el idioma, la pasión y la nostalgia. Redescubrí Aden… en tu propio idioma. Bienvenido a La Era de Einhasad.  
    • English you belarus retard ) Seems you so desperate and angry cant even speak back in EN, well guys you see how its easy to destroy scammer xD
    • Чувак) мне на него насрать давно, ты не мне сделал подлянку а людям которые купили и используют. Я его удалил год назад) когда закрыл продажи.   мне вообще похер кто ты и что ты.    Можешь сесть и попрыгать на тот же член на котором ты прыгаешь все это время) и этой версии более 3х лет) ты откопал залупу мамонта , поздравляю)) кто скачает это дерьмо используйте на свой страх и риск)) кто знает что там наворочено)))  удачи в шаринге обиженный жизнью неандерталец.   Можешь лизнуть мое очко на прощание.
    • Rosyk or rusik or whatever u blaim me that my mouth stinks but I assume you the one who stinks and your perfect pack will be now shared and you can suck a DICK )  https://eu2.contabostorage.com/d4b39866f6bb4084b6c969ec8fe20063:kita/Lucera_Classic_Remaster/Lucera Classic Remaster Server and Datapack files.rar  https://eu2.contabostorage.com/d4b39866f6bb4084b6c969ec8fe20063:kita/Lucera_Classic_Remaster/Lucera Classic Remaster Eng Client.rar Drama link    For this crap u need Lucera 2 classic license ) people paying 300 euros for this shit  lol Some Shit will come out soon mxc website need shake it a bit coz getting boring here )    Whats happen rosyk lost speach  xD Your pack was downloded  29 times bussines  not going as plan xD?
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock