Long running thread doesn't create memory leak. It is what you do inside it. Technically memory leaks happens when garbage collector could not collect free space, as the space is marked as being used. i.e. if references are held.
Now in a long running thread, you could have an object reference present for the lifetime of the thread. This object itself could be expensive. This is the case in first link you shared(threadlocal holding transitively all the references)
On your second link, the problem seems to lie somewhere. Here what I generally do if I suspect memory leak
- Use jmap to get count of each class instances
- Force full GC
- Again count the instances of each class, these are the objects GC was not able to clean
Repeat multiple times, you will notice some objects, which should have been cleared. This will give you some idea. Following those references in code you can get some idea.