Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Can you please explain how singleton is use full for creating database connection?
How it will work in multithreaded environment while creating db connection and closing the connection? Once connection is closed will it gets disconnect from database?
You should normally use a "connection pool" when managing database connections in your Java applications. Creating connections is expensive / heavy so you really don't want to be creating them time and time again, especially for a busy site (the performance drop will kill it).
The manner in which you acquire the pool reference depends on the type of application (managed like servlet/JSP or a standalone application) but search around for "datasource". Also have a look at this answer.
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 4 years ago.
Improve this question
In an enterprise back-end Java application, I have a requirement where some part of code calls various API which are independent of each other. On receiving response, I am utilizing them and passing data to requester.
For this, I have implemented callable based multi-threading (using Executor). But a colleague is stating that implementing multi-threading would make my code responsible for managing resources and not the Web App Container which can lead to performance issues.
So I wanted to know, what is the impact of implementing multi-threading in my code? And how can I make sure that resources are managed properly without impacting overall application.
There are a some different aspectes mixed together in your question. Creating threads on an application server is not prohibited because it could cause performnce issues. It's more that the server itself is responsible to manage the system resources. Spawning own threads, of which the server is unaware of, can not be managed by the server. See this page for more info about the topic.
Using an thread-executor that is provided by the platform, is very valid an could be used to implement multi-threading nevertheless. See here for example.
Another aspect of multi-threading is indeed performance. Creating threads comes with a certain cost and creating too many of them may lead to an overhead in conext-switching. The trade-off between pralellism and having to manage a lot of threads has to be consireded by the developer. Again this is why application servers, manage their own thread-pools.
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
My application is installed on a customer linux machine as a service.
From time to time he complains that the application stops.
The thing is that I can see from my application logs that the service is stopped gracefully (not crashed), but he's saying he didn't stopped it.
How can I tell who caused my service to stop?
My application listen to a configured port via socket, if someone writes to this socket - the application stops.
The customer say that there's no automated process that might cause the service to stop.
If it is an actual graceful shutdown, the culprit can be found by looking in the history. If it's the fault of the system, you should be able to correlate the time stamp of your application shutdown, with an event in the sys logs. If it's caused by something external, you might want to increase your logging on incoming connections.
This could be because of some extreme resource starvation. Ask your client if he is running out of RAM and swap space.
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'm using ServerSocket for creating a server.
I must create a new thread for each client or is it possible&safe to use only the server's thread?
If you just use the server's main thread, then only one client will ever be able to connect, becuase the thread is busy with the only client connected. After that client disconnects, the server can take another client, but you want to be able to accept clients constantly. Thus you need to spawn a thread for each client.
If you use only the server thread you will be able to manage only one client for time. I suggest you to use Executors class in order to create a pool of thread. The pool thread can manage multiple connection like the ExecutorService javadoc shows.
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
how to use JNI in JSP page?.In net i found that
1. because if anything goes seriously wrong in the C part of your application, it will very likely crash your J2EE server, downing all other web services and applications it is running.
because the 'reactivatable' nature of web applications means there is no guarantee that a static initializer will not be executed more than once during one JVM run.
Unless you're confident of the reliability of your JNI-linked library, I'd strongly recommend not doing this, for the reasons you've identified.
I'd recommend decoupling the application server from your native code, and make the native library available via some remote mechanism (e.g. web service / REST / simple socket). That way you've isolated the app server from any fatal problems related to the native code.