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

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

    • try this one instead. The one he shared affects every single NPC/player character in the game, the one I posted only affects player characters  https://drive.google.com/file/d/1UtccbD9e50x3WEnQBab2PTZnBHwpcGYM/view?usp=sharing or perhaps i misunderstood; if you could please post a full explanation of the problem you're having with the files, unfortunately i think whatever you're using to translate to english is a bit bad
    • <dailyReward days="28" autoOpen="true" minimumOnlineTimeSeconds="30" oneRewardPerIP="true" resetIfMissDay="true">   For now, I have these settings in the XML—this is the V1 version I created, though I plan to make further improvements over time. Of course, I’ll also add more protections—MAC, HWID, and perhaps others like account-based restrictions—to make it more secure. We can also implement non-tradable items to further enhance the system's security. I’ll keep posting updates and refining both the system and the interface. I might make a video tomorrow; if you look at the top, you'll see the "auto-open" feature can be toggled on or off, allowing users to rely solely on the `.daily` command. Cheers! Note: If I sell it in this state, I’ll provide support and roll out updates to users. I’m not forcing anyone to buy anything; I’d even provide the patch files so that anyone with the necessary skills can add features, modify it, or improve it further.
    • If the problem is that the target is lost, the action of aiming at another character, upon losing collision, does not allow aiming.   This one works as it should, allowing you to target characters
    • MICROTEXT AND WATERMARKS BREAK MOST RENDERINGS Microtext and watermarks aren’t just small decorative details. They are one of the most common reasons a document fails verification, even when it looks decent at first glance. The issue is that these elements are almost impossible to reproduce “by eye.” Microtext requires precise geometry and legibility at a very small size, while a watermark needs the correct density, transparency, and accurate placement relative to other security features. Any deviation becomes obvious during detailed inspection. ▪ What’s most often done wrong: - microtext is drawn too thick or blurry - the watermark is made either too visible or almost invisible - the positioning between microtext and watermark is ignored - the original printing technology isn’t taken into account when choosing density and shape - The stronger the document’s security features, the less room there is for approximation. What matters here isn’t visual similarity, but accurate reproduction of the original technical characteristics. If your document contains microtext and watermarks, this is always an area that requires extra attention. Write to us in DMs. We’ll review your case and point out exactly which details need the highest precision during rendering. › TG: @mustang_service_ms ( https:// t.me/ mustang_service_ms ) › Channel: Mustang Service ( https:// t.me/ +JPpJCETg-xM1NjNl ) #drawing #microtext #photoshop #editing #watermarks
  • 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..