Jump to content

Run some code in background


Toinou9120

Recommended Posts

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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