Posted October 15, 20178 yr Hello, In my mod, I use the Java URLConnection to connect to a website and get some stats. I connect to the website with a TickEvent.ClientTickEvent event, but it takes like 2-3 sec so the game freeze during this time. Is this possible to run this code in a background thread or something that will not freeze the game ?
October 16, 20178 yr Just make a daemon thread. public class StatDownloadThread extends Thread { public StatDownloadThread() { this.setDaemon(true); this.start(); } public void run() { //Fetch stats. } }
October 16, 20178 yr Author 10 hours ago, diesieben07 said: This is definitely not a "just do X" question. Multithreading is a difficult topic, especially in Minecraft, since most of the game's code is not threadsafe. Yes, you need some kind of thread, but you almost never want to use the raw thread API. Use an Executor resp. ExecutorService. URLConnection is terrible. Use the Apache HttpClient that is included with Minecraft already. Thank, I will try this.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.