Skip to content
← Back to Community
How do I run two codes at a time (in java)
Profile icon
plscodeinjava

The title basically says it all, when you press the run button two files run at the same time... Any help?
Thanks,
Amaddentcsec

Answered by PattanAhmed [earned 5 cycles]
View Answer
Voters
Profile icon
plscodeinjava
Comments
hotnewtop
Profile icon
PattanAhmed

@amaddentcsec Hi,
Check this website and Please don't forget to say your feedback in the Comments
Click here
Thanks!

Hope this helps

Profile icon
plscodeinjava

@PattanAhmed
Dang this looks like it will work!
Thanks!

Profile icon
PattanAhmed

@amaddentcsec Welcome!
Happy to help!

Profile icon
DynamicSquid

I don't do much java, but you can take a look at multithreading in java: https://www.geeksforgeeks.org/multithreading-in-java/

Profile icon
SixBeeps

Are you talking about having two separate instances running one file each, or one instance running both files at the same time?

Profile icon
plscodeinjava

@SixBeeps
running both files at the same time

Profile icon
SixBeeps

@amaddentcsec Yeah I understand that, but how many instances do you want running? Do you want to multithread (same instance) or just have two separate instances?

Profile icon
plscodeinjava

@SixBeeps
multithread i suppose

Profile icon
SixBeeps

@amaddentcsec Just to make sure that's what you want, what do you plan on achieving by running multiple files? Is is for something like a server and a client?

Profile icon
plscodeinjava

@SixBeeps
I'm making an ascii game in java....

Profile icon
SixBeeps

@amaddentcsec Then why do you need to create two separate files? Are you creating numerous classes?

Profile icon
plscodeinjava

@SixBeeps
One file for getting input, one file to run the game

Profile icon
SixBeeps

@amaddentcsec So you want to check for input while you do stuff with the game? You should do that in one file, listening to KeyEvents. I don't think Repl.it supports it, but it's worth looking in to: https://stackoverflow.com/questions/18037576/how-do-i-check-if-the-user-is-pressing-a-key