Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am making a thread that reads from a serial port and writes to a PipedOutputStream. This way I can read from the port with scanners and such. I am wondering if code like this would slow down the JVM:
while (serialPort.isOpened()) {
while (serialPort.getInputBufferBytesCount() > 0) {
pipedOutputStream.write(serialPort.readBytes());
}
}
While running in the first while loop, it would just be looping really fast until something comes in, should I add some delay there (like 10ms) so it isn't going so fast or does a while loop in this fashion not cause any noticeable lag?
The serial port does not have any InputStreams that I can read from, that is why I have to make this thread. I am using https://code.google.com/p/java-simple-serial-connector/ for my serial interface.
Have a look at the documentation here it will likely help you develop a better notification based solution: https://en.wikibooks.org/wiki/Serial_Programming/Serial_Java#Event_Driven_Serial_Communication
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 days ago.
Improve this question
I have an api which allows me to run 180 requests every minute. However, if I request more than 50 times in a second, I will get temporarily banned. I have a thread class which sends the api request and performs and action on it. Assuming the class is called ApiRequestThread, what would I do? This is in java
I have used a mix of double guava ratelimiter but I wanted to know if anyone had any better ideas
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to learn multi-threading in java.
Suppose I have a very big application with 100 running threads trying to execute a synchronized method which inserts a row in database.
As, the method is synchronized so only one thread will get the lock for that method and rest 99 will wait.
Only 1 thread is able to edit the Database and rest will be waiting. It seems a slow process. As all the threads will be editing the DB one by one. Is there any other way or concept to safely edit the database in a faster way?
i will recommend u to read about isolation level in transaction to handle some cases in concurrent application https://en.wikipedia.org/wiki/Isolation_(database_systems), sometimes is handles by default.
if for isntance u only adding new rows in table u shouldn't care about it and remove synchronized
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have 1000 images, each of them signifies a state at the time step. I would like to create an application that allows us to use a slider move through time steps, eventually being able also to see some information about what is going on in the image (like region size ect). I created the algorithm which creates generates and analyzes images in Python and I guess I will try to create UI in Java. Any recommendations on how to approach it? ( I am not very proficient in Java but I understand the basics). I attached the general view of what I want it to be below:
Try Tkinter, it is a very easy to use UI creator in python.
https://docs.python.org/3/library/tkinter.html
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Im my level menu (I'm using libgdx), I would like to lock and unlock game levels.
Alowing player to unblock each game level after finishing the previous?.
Can someone point me an example?
Thanks in advance for any help comming this way.
PEACE!
This is just logic stored in variables between sessions.
Loop all of your levels
If the loop index is lower then or equal than your variable "howManyLevelsComplete" make then unlocked. Else you lock them
Save the "howManyLevelsComplete" variable to Preferences so you can keep track when the application restarts.
I wont provide code for this since it's basic game logic.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Basically what I am asking is how do games check what the user inputs all the time, not just when the user is asked to input an integer or a word but I am ALL the time.
Example: Runescape, Minecraft, WoW, any game developed that uses text based communication always has that function that if you type in the pretty box it spits out what you said in a world chat box, how do I do that as such (Not a world chat box) but simply a put out.
Simply put, by polling. Games use loops which run 20+ times a second and check for whether the user is causing input via keyboard/mouse.
There are hundreds of great tutorials