Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible to send a Java thread instance in an HTTP request?
No. A Java thread cannot be serialized, and therefore it cannot be sent outside of the JVM in which it was originally created.
(For a moment, just imagine what would be involved in moving a thread from one JVM to another. What about the static variables it might refer to? What about the other threads that it might to interact with? The problem is intractable.)
Actually I am working on clustered servers and want to execute my some threads(defined Jobs and other heavy task) on one server(called it back office node). So is there any way to do that.
OK, so that's a different problem. You actually need to execute tasks remotely, not pass threads. ('Cos you can't pass threads.)
Yes, there are many ways to send tasks to be executed elsewhere ... in the general sense. What you need to do is to express the task or task description in a form that can be serialized in some way (Java Object serialization, JSON, XML, etcetera) and then pass the serial form to the server that is going to execute it. The server would be responsible for managing the thread that does the execution.
Caveat: This is not going to work well if the task is needs to refer to a whole lot of data / objects on the machine where you formulated the task. That is going to involve serializing / passing all of the data OR figuring out some way for the backend to "call back" to get the specific data items that a task needs.
Related
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 been working on AWS Lambda function with some custom Java codes. It's codes had to get long execution time be required but Lambda has execution timeout as 900 seconds of maximum. So I intended that to be saved memory state of process to S3 as file before the timeout and then load that file to be executed from S3 on next execution time.
How to save all state of process to file and then load to execute that from saved process state?
Your JRE won't support such a risky feature but if you're looking to run extraneous tasks I would not suggest saving process states anyway. If you can add some code and details you'll get a more precise solution to your problem, however some basic pointers...
Make sure the functions you're processing data with can be dynamically paused and started
Write functions to save/load data from a file in any format (json, csv, etc)
Write a function to identify when your dp task is complete
Hard code a limit to load, process, then write in that order
Batch the process in series until you're notified that it's complete
Again this question is really ambiguous so my answer may not be at all what you need. In either case what you want to save is data, not processes. In theory the computer itself is capable of saving the states of all registers, the stack, and program counter in assembly but that's a pretty big no no for a lot of reasons that aren't really part of this discussion
Sorry for my ambiguous question to you!
I knew how a application basically save it's data to file and restore that next runtime.
But my work about the question is wrapping Lambda handler to be included ETL migration job application that has to take time over Lambda maximum timeout.
I was already developed Lambda handler building framework being able to include ETL job and deploy the handler to lambda function but I didn't solve that problem of Lambda timeout.
Meanwhile, I thought about like 'jmap' tool. I just guessed that if 'jmap' can dump heap memory, even it could be restored from dumped file.
As collectively thinking, There isn't a way to solve that problem with my guess.
So I could like better to make application data store architecture in ETL job.
Because of ETL job program is built by other ETL solution, I feel some inconvenience.
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
In many examples that discuss synchronization, it is mentioned something to the effect, "This will work in a single-threaded application, but if multi-threaded..."
I am puzzled because it seems to me possible, although perhaps incredibly unlikely, that even in a single-threaded operation, there can be problems similar to those mentioned in multi-threaded applications.
Say you have an object that has a status field that reflects whether it has been placed into a queue. Pseudo-code would be: object.setStatus(INQUEUE); placeInQueue(object);
Now, if it was somehow possible for the status to be successfully set but the next line of code "silently fail" and the program continue, would we not have a problem wherein we think the object is in the queue but is not? Maybe the idea that we could have a silent failure is false.
But if it is somehow possible for the above problem to occur, how would we make so that the two lines of code either always both executed or both failed?
Logic bugs, that is a flaw in the algorithm, can and regularly do still happen in single threaded applications. If such a problem exists in a single threaded implementation of the algorithm, then it will only get worse when one tries to make it multi-threaded.
The quote "This will work in a single-threaded application, but if multi-threaded..." was talking about a class of problem that gets introduced by the nature of being concurrent. For example, if I was in the kitchen baking a cake by myself I would not have to worry about bumping into another chief. I would however have to still worry about burning my hands on the oven and not bumping my hip on the counter.
The scenario that you describe using a queue, that is backed by disk is another example of parallelism. Even though our application logic is single threaded, other processes can be writing to disk while our process is working with the queue and so it is possible for the disk to run out of space at no fault of our program. Handling such problems can become quite involved, the two basic approaches are to either lock out a resource for a period of time or optimistically assume that one will succeed and then handle an error when it fails later. The example that you gave was an example of the later, only without the error handling. A silent failure in that scenario can happen in real systems that ignore the problem, and they are broken.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am writing a system core (server) that is to handle multiple connections and requests. Lets suppose my server has a client connected and is ready to communicate. My question here is, how would i make the server know that client wants to send some data or reversal. Since read blocks until it receives data... so how to manage between the read and write operations to sockets if we don't know what the remote system at other end expects?
I can see a way around it using multithreading. Any way around please???
Multithreading is the only sensible way around this (in fact, it's one of the absolute classic cases where threading is required) - you'll have to create a new thread for each connection.
You may wish to do this directly, or you may wish to use the constructs available in java.util.concurrent (which I'd recommend) - thread pools for instance. One sensible approach might be to use a fixed thread pool to make sure the number of threads doesn't grow too ridiculously large, and then spawn threads off there as required.
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 9 years ago.
Improve this question
I'm attempting to build a Java Servlet task that has a runtime of about ~15-20 minutes that takes arguments from a HTML form. I have a couple of questions regarding this:
Will the task continue to run even after the user closes the browser? I Googled this and it seems the process will continue to execute even after browser close. I just want to confirm this.
While searching for the answer for the above question, I came across a post (or a couple of them) that stated that for such 'intensive' (I would consider mine intensive as it takes around 15-20 minutes to complete) tasks, it's better to have a separate program run the task than containing it in the servlet program. So, do I just execute another Java program from the servlet class?
And now for my final question, will multiple user requests be processed independent of each other? As in, will the servlet have a separate thread or instance for each request? If so, will my execution of another Java program from the servlet class lead to any problems?
There are a few items to discuss, each with their own (part of a) solution:
Do you really want the task to continue if the browser closes? Spawn a new thread for the task (Trying to write to the browser outputstream when browser is already closed will make the thread die in an exception) See Executor
Do you want concurrent requests to be handled in parallel? How many in parallel? See ThreadPoolExecutor
Do you want feedback to the browser (user) during the long running task? See Async servlets
The servlet container will make sure that parallel requests are handled concurrently, each in their own thread. But they will share the instance of the Servlet class. Therefore, you have to make your code thread safe.
About running a 'separate java program' or keeping the task in the servlet: it is best practice to separate different tasks in a program in different sections. Creating a new class for your long running task is better than keeping it in the servlet class. See Separation of concerns.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am not sure if this is the correct forum to ask this but i am not sure where to ask either. So here is my question:
what does "deep ping" mean. I tried google but still did not get any information about it. Also who does deep ping mean in web servlet`s context. Thanks.
I'm not sure it's the "official definition" if there is such a thing, but I've head "deep ping" used about functionality that allows you to (in contrast to a regular ping) send a message to the server that passes through as much of the webstack as possible before returning an "ok" response.
As an example, you can make a ping transaction that passes from the network straight down the stack to the database and there does a dummy select to read the ok from a dummy table and return that result. That allows you to (in contrast to a "normal ping" that tests only the network) have confidence that all layers in the application including the database are actually alive.
- Ping is one of the most basic and useful network commands. It sends request to networked computer and waits for response. It’s easy to ping single PC but it’s pain to ping dozens (or even hundreds) of them.
- The process of Pinging the entire Subnet which can have N nos of PCs are known as Deep Ping. Network scanners are usually used to do this....