{"id":464,"date":"2013-08-23T14:07:55","date_gmt":"2013-08-23T12:07:55","guid":{"rendered":"http:\/\/www.epischel.de\/wordpress\/?p=464"},"modified":"2013-09-18T13:33:09","modified_gmt":"2013-09-18T11:33:09","slug":"default-timeouts-for-network-connections-in-java","status":"publish","type":"post","link":"https:\/\/www.epischel.de\/wordpress\/2013\/08\/default-timeouts-for-network-connections-in-java\/","title":{"rendered":"Default timeouts for network connections in Java"},"content":{"rendered":"<p>You often find the answer to &#8222;How do I set default timeouts for (outgoing) network connectins in Java&#8220; is<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">java<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"java\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #003399\">System<\/span>.<span style=\"color: #006633\">setProperty<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;sun.net.client.defaultReadTimeout&quot;<\/span>, <span style=\"color: #0000ff\">&quot;30000&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #003399\">System<\/span>.<span style=\"color: #006633\">setProperty<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;sun.net.client.defaultConnectTimeout&quot;<\/span>, <span style=\"color: #0000ff\">&quot;30000&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>But this may or may not work. Because, <a title=\"See answer to Bug database entry\" href=\"http:\/\/bugs.sun.com\/bugdatabase\/view_bug.do?bug_id=6245589\">as stated by Sun in 2005<\/a>:<\/p>\n<blockquote><p>Yes, it [the default timeout] is cached, or more precisely it is looked up only at startup time. This is by design.<\/p><\/blockquote>\n<p>Playing around with the code in the bug database entry linked to above and netcat, I found that it is also true for Java 6. Chances are high that it is true for Java 7, too.<\/p>\n<p>What is meant by &#8222;startup time&#8220; is using some network connection, e.g. HttpURLConnection. That means if there has some network connection been used before the properties are programmatically set, no network connections will use these timeout values!! If you set these properties in the <a href=\"http:\/\/docs.oracle.com\/javaee\/6\/api\/javax\/servlet\/ServletContextListener.html\">JEE ContextListener<\/a> or some startup-servlet they may have no impact anymore because your web container may already have used a network connection. Better use the commandline to pass these parameters.<\/p>\n<div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"<p>You often find the answer to &#8222;How do I set default timeouts for (outgoing) network connectins in Java&#8220; is [sourcecode language=&#8220;java&#8220;] System.setProperty(&#8222;sun.net.client.defaultReadTimeout&#8220;, &#8222;30000&#8220;); System.setProperty(&#8222;sun.net.client.defaultConnectTimeout&#8220;, &#8222;30000&#8220;); [\/sourcecode] But this may or may not work. Because, as stated by Sun in 2005: Yes, it [the default timeout] is cached, or more precisely it is looked up only&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"webmentions_disabled_pings":false,"webmentions_disabled":false,"footnotes":""},"categories":[3],"tags":[46,120],"series":[],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-java","tag-configuration","tag-java","kind-"],"kind":false,"_links":{"self":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/comments?post=464"}],"version-history":[{"count":8,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":484,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/464\/revisions\/484"}],"wp:attachment":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/media?parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/categories?post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/tags?post=464"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/series?post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}