Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.2] Join the minecraft thread from another thread


Recommended Posts


I have two thread : The first one is the one of minecraft, the second one is async thread that I created to do something on the web.

I would like that when the second thread is done, the first thread execute a method ( and not the second thread because minecraft really doesn't like when you use method using another thread).

Before the second thread ended, the first thread must continue working.

Does anyone have any idea of how to do that please ?


Edited by uiytt
Link to comment
Share on other sites


You could consider using the packet receiving system to do that.

Any time a packet is received, it is in a network thread.  The network thread creates a Runnable lambda which is then executed in either the client thread or the server thread.

Some more info here:



There's probably a way for your second thread to add your own Runnable lambda to those queues without using packets.


Alternatively, you could perhaps subscribe to a Tick event on the server or the client, and every tick check your second thread to see whether it has finished executing or not.



  • Like 1
Link to comment
Share on other sites

13 hours ago, TheGreyGhost said:

There's probably a way for your second thread to add your own Runnable lambda to those queues without using packets.

There is.

Various elements in Minecraft extend the ThreadTaskExecutor class, which in turn implements Executor and thus lets you run arbitrary Runnables (or even use CompletableFuture).

For the client side thread that would be the Minecraft instance, for the server it would be MinecraftServer.

  • Thanks 1
Link to comment
Share on other sites

Well I tried :

Minecraft.getInstance().runImmediately(new Runnable() {
	public void run() {
		MultiPlayerGui.this.minecraft.displayGuiScreen(new ConnectingScreen(MultiPlayerGui.this, MultiPlayerGui.this.minecraft, server));

And it's really weird...

In my console, I receive everything from the server chat. But on my game, it's stuck on loading the terrain infinitely !!!

MultiPlayerGui is my custome class but the rest is not..

I don't undersant why O_o

Link to comment
Share on other sites

7 hours ago, diesieben07 said:

Any reason you are using runImmediately? Whats the thread that this is called from?

A thread that I created to check for my server's information.
If I use the screen directly from my thread, minecraft will crash..

Edited by uiytt
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.

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 Privacy Policy.