4

I'm coding my server in java, and through the day, my server has to connect through 5 different proxies at once to other servers and gather data. However, reading about java proxy settings through stackexchange, I see that when you set a proxy, its effect is VM-wide, meaning whatever network activity that .jar was doing, it will do it through a proxy if somewhere a different thread sets a proxy setting within the jar.

I'm currently using this method of setting a proxy, which according to some tests it's actually pretty functional and works fast.

    System.getProperties().put( "http.proxyHost", host );
    System.getProperties().put( "http.proxyPort", port );

However, I can't really afford having 5 jars doing the same thing with different proxies, I tried it to, it would be a simple solution however I can't afford to use that much ram only for this, as my server is huge.

4
  • No idea, but maybe this class will interest you. And even more this one Commented Mar 15, 2014 at 19:31
  • I suggest using AsyncHttpClient which has support for http proxies github.com/AsyncHttpClient/async-http-client Commented Mar 15, 2014 at 19:34
  • Thanks for the suggestions. I'm reading upon the java Proxy class, I read it can be used with the URLConnection class and it doesn't say anywhere that the effect will be VM-Wide, the way you use that class wouldn't make sense to have a vm-wide effect either way. Commented Mar 15, 2014 at 19:57
  • That's correct. It only applies to the connection(s) you use it with. The terminology in your question is incorrect. System properties are JVM-wide, not per jar. Commented Mar 15, 2014 at 22:38

2 Answers 2

2

You need to call each connection with its own proxy settings. The Answer here by NickDk defines how you can call a url with its own proxy settings. You will need to do the same with each of your 5 proxies separately.

Sign up to request clarification or add additional context in comments.

Comments

0

here is described the use a library embeded in the JRE, able to handle "proxypac" files in wich any combination of proxies can be defined.

since it is embeded in the JRE, standard ways to configure a Java application with a proxypac file (standard launch optional parameters) might exist, but I am not aware of it.

Howhever the solution described in the link provided should fit your needs since your usage is programatic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.