You can garbage collect in Java simply by calling System.gc()
but sometimes this \"stalls\" the application. Is it a bad idea to garbage collect like this and a
Apart from what was already said so far, the whole idea is horribly flawed because you sadly miss one important detail:
While a full GC is running the application will be stopped! (at least currently on a modern Hotspot VM - and what else would you be using?)
There's a concurrent mark & sweep implementation in hotspot (though afaik not activated by default), but that incurs some extra overhead and still has to stop all threads before doing the sweep. So basically unimportant from which thread you do System.gc() the VM will wait for all threads to reach a safe point, stop them and then do the collection. So using a thread is completely useless.