Jump to content

Multiple questions about MC + Shutdown + Custom Threads


CAS_ual_TY

Recommended Posts

Hi,

the mod I am working on downloads textures at runtime (used for Screen, not Items/Blocks ofc). This must be done in seperate threads, as otherwise the game freezes for the duration. Now, I have some experience with Multithreading, I know how to make things thread safe and all the basics you need to know for that. My goal is to use a Thread Pools like implementation, as there are multiple tasks todo (Download, Resize, Modify image entirely ...), and sometimes they need to be done in a specific order.

The main question would be: What to do when Minecraft shuts down. All the tasks are short, so ideally I would like to wait for them to finish, the task queue can just be discarded in that case. There are some tasks which I do not want to see interrupted in some circumstances (eg. while writing to a file). I dont know of any MC functionality that I can use to ensure that.

So I did some research and might go for a Shutdown Hook. This leads me to my 2nd question: Would it be bad practice in this specific scenario to have the shutdown hook thread just wait for the worker threads to finish (with a max wait time ofc)?

If there are better ways of accomplishing what I am trying to do, please let me know

Thanks!

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.