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

    • @Darafamboos let him know that this is already shared
    • Selling for 35 us umodel that opens any ukx , utx and static meshes from samurai updat 542 protocol . Leave me a pm if needed. 
    • TG Support: https://t.me/buyingproxysup | Channel: https://t.me/buyingproxycom Discord support: #buyingproxy | Server: Join the BuyingProxy Discord Server!  Create your free account here
    • NEW HIDDENSTASH KEY SYSTEM INTRODUCED TO THE SITE   **Earn While You Spend - Introducing HS Cashback!**   Every purchase on our site now rewards you with **HS Keys cashback**   EVERY ONE WHO REGISTERS IN SITE UNTILL 15TH OF MAY GETS 2000 HS KEYS IN HES BALANE   Here's how it works:       **1 USD = 1000 HS Keys**   **Get 3% cashback** on every purchase   **Use your HS Keys to **save on your next order**   ---   ### ⚡ Why this is awesome   * Every order gives you value back   * Stack it with promos & HS usage   * Turn your spending into future discounts   ---   ### Example   Spend **$10** → Get **300 HS Keys** back   Spend **$50** → Get **1500 HS Keys** back   ---   ### Smart system (built for fairness)   * Cashback is rounded to keep things balanced   * Prevents abuse from tiny orders   * Rewards real buyers   ---   ### Start earning now   Every purchase = progress toward your next discount   Shop now and build your HS balance!   #cashback #gamingdeals #d2r #rewards #loyalty   Stay safe out there, heroes - and happy hunting! www.d2rhiddenstash.com     We just launched our new Affiliate Program — and it’s the easiest way to earn HS Keys.   Invite your friends using your personal link.   Example: If your friend spends $10 → you get 300 HS Keys No limits. No effort. Just share your link.   Get your referral link here: www.d2rhiddenstash.com/profile     Start earning today
    • It’s time for something new to rise. In a world filled with short-lived projects and empty promises, Emerge was created with a different vision — a vision built on experience, precision, and long-term commitment. This is not just another server launch. This is the beginning of something that is meant to last. 🌑 Eclipse x10 – A New Beginning Eclipse x10 is designed for players who seek more than just fast progression. It is built for those who value competition, balance, and a real Lineage II experience. From the very first day, every system has been carefully adjusted to provide a smooth and fair journey — where both solo players and clans can thrive. No shortcuts. No chaos. Only a structured and competitive world. ⚔️ What Awaits You • A balanced mid-rate environment (x10 core progression) • Stable and optimized gameplay • Fair systems with focus on long-term play • Competitive PvP and rewarding PvE • Active and dedicated administration • A project built with vision, not temporary hype 📊 Server Rates Basic: EXP/SP: x10 Adena: x5 Drop: x5 Spoil: x5 Secondary: Quests: x1 Seal Stones: x5 Life Stone Drop: x1 Enchant Scroll Drop: x1 Bosses: Raid Boss EXP/SP: x1 Raid Boss Drop: x1 Epic Boss EXP/SP: x1 Epic Boss Drop: x1 Enchant: Safe: +3 Max: +16 📅 Launch Information Grand Opening: 5 June 2026 The countdown has already begun. Clans are forming. Strategies are being prepared. The question is — will you be ready? 🔗 Join the Community Every strong server begins with a strong community. Be part of it from the very start. 💬 Discord: https://discord.gg/l2emerge 🌐 Website: https://www.l2emerge.com  
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..