Set SO_LINGER socket option to ServerSocket in java [closed] - java

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
How to set SO_LINGER socket option to ServerSocket? Should i extend SocketImpl class. But there are many abstract methods in SocketImpl class.

Set it on the Socket that you get from serverSocket.accept().

You can't set SO_LINGER on a ServerSocket. It doesn't make sense.
I'm wondering whether you even know what SO_LINGER is for. It is a very rarely used technique for enforcing a close timeout on connected TCP sockets, or, unfortunately, for forcing them to reset the connection when closed, which is an operation by far best avoided for many reasons, much-abused, and little understood.
You almost certainly don't want to use it at all on any socket whatsoever.

Related

HttpClient class AbstractConnPool becames too big,how to solve it ? [closed]

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 3 years ago.
Improve this question
The class org.apache.http.pool.AbstractConnPool has this map field:
private final Map<T, RouteSpecificPool<T, C, E>> routeToPool;
If I use a lot of proxy ip, the map size will became bigger and bigger, this will cause oom.
How to solve it?
To be honest, I never had this issue working with an Apache HTP Client. Looking at your memory dump at Httpclient out of memory I see "104655 instances of class org.apache.http.pool.AbstractConnPool$1" which is an anon inner implementation of RouteSpecificPool which is the value type of the field you mentioned.
So the question is, how do you use the client? The connections have to be released at some point and unused and/or expired connections will be cleaned up.
Do never keep connections in the pool forever or do a keep alive for connections you do not use any more! Such things in combination with requests to high diverse targets (aka routes). You have to configure timeouts for usages (see also Apache Httpclient Connection not Released)!

How to exchange objects between client and server without using stub in rmi java? [closed]

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 2 years ago.
Improve this question
I'm trying to send an object from client side to server side in order to modify its attributes and send it back from server to client - but without using a stub.
Any ideas?
Sure:
define your own protocol to enable remote calling
serialize the object on the one side into a stream of bytes, or more 2017ish: into a JSON string
send the bytes / string to the other side
deserialize, update; serialize and sent back.
That is a pretty generic answer; but given your extremely broad input; the best you can hope for (imho).
Further reading: on protocols, on serialization.
You don't need a stub class in the sense of generating one with rmic. Study the preamble to the Javadoc for UnicastRemoteObject for the conditions under which a dynamic stub is generated automatically.

How to call a Thread in a method [closed]

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 6 years ago.
Improve this question
I want to programmatically move a Thread in another method. How I can do this?
that's entirely not possible in Java.
There are some ways around that - using tools like AtomicReferences, AtomicBoolean, wait/notify or Channels. With these tools, you could inform the other thread that it should do something specific.
Another approach would be to copy SwingUtilities invokeLater - like here: http://www.javamex.com/tutorials/threads/invokelater.shtml
However, I would like to ask the question why that method execution needs to be run in a specific thread? Wouldn't just another (new thread) be fine too? That should significally simplify your problem. In that case, just start a new thread to call that method

Synchronization paragraph from java documentation [closed]

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
everyone!
I am reading java doc from this:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html
Could anyone,please, tell more about
The Java programming language neither prevents nor requires detection
of deadlock conditions. Programs where threads hold (directly or
indirectly) locks on multiple objects should use conventional
techniques for deadlock avoidance, creating higher-level locking
primitives that do not deadlock, if necessary.
Thanks.
It means that "Do not expect java to handle OR avoid deadlocks for you. If you do not write your code properly then there is no way java will tell you in advance. So, it is your responsibility to make sure your code does not cause any deadlocks".
Basically, this paragraph states that Java won't handle deadlocks for you - it's your responsibility to avoid them.

Silently Opening HTTP Connections in Java? [closed]

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
How would I go about silently opening up a HTTP connection to a certain website in Java?
I tried .openConnection() and it didn't work.
You need to find out why .openConnection() isn't working. Catch the exception thrown by that call and print out the exception's full stacktrace. That should give you the information you need to start diagnosing.
The javadoc for URL.openConnection() says this:
"It should be noted that a URLConnection instance does not establish the actual network connection on creation. This will happen only when calling URLConnection.connect()."
That call can occur explicitly or implicitly; i.e. when you attempt to read the response status, headers or body. Read the javadocs for URLConnection and HttpURLConnection for more details.
So it sounds like openConnection is working ... but it doesn't do what you expect it to.

Categories