How does JGO use long polling?

I’m wondering exactly how the “there are X new posts” notification at the top of this very site works.

I know the basics: it uses ajax to request the number of new posts, and then I think it uses asynchronous long polling on the server side to only return the number when it changes.

But on the server side, doesn’t that mean there are a bunch of threads (or maybe a thread pool) waiting on that update? More to the point: if I refresh the page 500 times (sorry Riven), doesn’t that mean there are 500 threads (or thread pool tasks) waiting around- 499 of which are now pointless, since I’ll only ever receive the last one? Isn’t that a potential memory leak- if I get a bot to constantly refresh the page and create more of those waiting objects, won’t it eventually break?

I’m asking about this site, but what I’m actually trying to figure out is the correct way to do this in Spring. I’m not sure how different JGO’s php server is from a Java server, but I’m hoping the above questions are general enough to apply to my situation as well.