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
Working on a small internet application, I need to deal with a service out-of-service situation. What is a good approach of retry after an exception?
The simplest solution (though maybe not the best) would be to return an error page to the user (with status 503: Service Unavailable), and tell him he should try again in a few seconds.
Depends on how long your application will be out of service but I will go with one of those :
- if the interruption is short less than one minute, loop and try to call the function/service/ ....
- if the interruption could be longer, you could use a JavaScript routine that would automatically refresh the page ... every 60s
- As Eran Zimmerman's answer, display an error page and advice the user to try again later
You don't want to beat your application to death with repeated retries. Returning an error page is not that bad an option. If you must retry (you have some flaky service where you can't cache the results) then use a backing-off approach where with each retry you double the time until the next try.
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 years ago.
Improve this question
In a spring boot web application, I need to be able to do two tasks.
Tasks
Always check on the serial port if there is some data to read. Somebody can have passed a card on the scan. I think this task needs to start with the application.
If a new member comes, I need to scan a card, task 1 needs to be suspended/stopped... if the card is not assigned to anybody, it's assigned to this member. Restart task 1.
I don't know what is the best way to do task 1 to facilitate task 2.
I see there are many possibility: #Scheduled, TaskScheduler who will execute a thread...
Any suggestions?
You should make one Thread that reads data from the serial port in a loop and dispatches this data as events when something usefull was readed to a proper service that will serve this.
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
I have an interesting scenario based question related to java threads.
Sam has designed an application. I t segregates tasks that are critical and executed frequently from tasks that are non critical and executed less frequently. He has prioritized these tasks based on their criticality and frequency of execution. After close scrutiny, he finds that the tasks designed to be non critical are rarely getting executed. From what kind of problem is the application suffering?
I have figured it out as "Starvation" but i am still confuse whether I am right or wrong.
Starvation is a reasonable term for what is going on here. However, your lecturer might have something more specific in mind (... I'm not sure what ...) so check your lecture notes and text books.
... i am still confuse whether I am right or wrong.
If you stated why you are confused, we might be able to sort out your confusion.
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
We are using quartz for a background server whose purpose is to systematically aggregate the data by applying some business rules. Essentially, we have three background jobs which fires m*n more jobs. Since we are a SaaS application so we have multiple tenants so we end up with (no. of tenants * (3 + m*n )) jobs. These are fired over ten threads and the triggers repeat indefinitely as we require them to be aggregated hourly due to business constraints. Note that once these jobs are fired at server startup they remain consistent, i.e. no new jobs would come. SO the final number of jobs are as mentioned above.
Each job hits the DB and some of them could take more than a second as well.
Could any of you suggest the best way to scale this. We could consider restructuring the code as well as this code was more of a POC and we really need to SCALE!!!
----------------------EDIT----------------------
From the responses so far received I would like to make the question more concise. There is this approach which we followed, i.e. using 10 threads we scheduled multiple quartz job at server startup and triggered them indefinitely to be run every hour. Do any of the members here have a suggestion here how to approach such problems in a more efficient manner, is quartz scheduler the best approach or use some other tools/ framework, maybe Spring batch..
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am struggling to understand why every time I use threads in java i have call the .sleep() method first. I would like someone to explain to me why is it useful to call the sleep method.
And what could happen if it is not called.
Thread.sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system. The sleep method can also be used for pacing, as shown in the example that follows, and waiting for another thread with duties that are understood to have time requirements, as with the SimpleThreads example in a later section.
For more information, please refer to this link: http://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
Sleep is used to pause the thread for x number of milliseconds, as specified in the documentation
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
1.Is it possible to acheive multithreading with single processor?
Multiprocessing : Several jobs can run at the same time.(So, it requires more than one processor)
Multitasking : Sharing of processor among various tasks, here some scheduling algorithms come in to context switch tasks (Not necessarily need multiple processor)
Multithreading : A single process broken into sub tasks(threads) which enables you to execute like multitasking or multiprocessing and their results can be combined at the end. (Not necessarily multiple processors)
Links:
http://en.wikipedia.org/wiki/Computer_multitasking#Multithreading
http://en.wikipedia.org/wiki/Multiprocessing
http://en.wikipedia.org/wiki/Multiprogramming#Multiprogramming
Edit : To answer your question , multithreading is quite possible with one processor
Yes, it is possible.
With a single processor, the threads will take turns executing. Exactly how this is implemented is up to the operating system.
If the work done is computation heavy, you will probably lose more than you gain because of the added scheduling overhead.On the other hand, if there is a lot of waiting, for example for network resources, you can gain a lot from using several threads on a single processor.
Yes it is possible.
The threads can get their turn in time-slice i.e. each thread can be executed for some particular interval and then other will get turn.
For more info.
Time-slicing
Preemption
Threads concept mainly used for acheiving the multitask in a single processor,to minimize the ideal time of the of the processor we are using the multithreading concept in java.