Jump to content

Recommended Posts

Posted

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 ?

Posted

Just make a daemon thread.

public class StatDownloadThread extends Thread {
	
	public  StatDownloadThread() {
		this.setDaemon(true);
		this.start();
	}
	
	public void run() {
		//Fetch stats.
	}
	
}

 

Posted
  On 10/16/2017 at 7:07 AM, 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.
Expand  

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.