Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Timeout für HttpUrlConnection

Empfohlene Antworten

Veröffentlicht

Hi,

ich hab eine Klasse die per HttpUrlConnection ins Internet verbindet.

Das ist nötig für mein Programm. Jetzt hatte ich heute morgen folgendes Problem:

Das Internet war nicht verfügbar und die Anwendung tut dann für 2-3 Minuten einfach nichts mehr.

Ich nehme an es gibt irgendeinen Standard Timeout.

Da 2-3 Minuten allerdins viel zu lang sind möchte ich diesen auf 1 Minute oder 30 Sekunden setzen. Wie kann ich das tun ?

PS: Fand keine Methode um Timeout für HttpUrlConnection zu setzen (HttpUrlConnection)

Benutze Java v1.4.2

Danke!!

Gruß Scratch

  • Autor

Jep, danke es funktioniert ...

Und nun die Lösung für alle anderen :mod:



// Set Timeout

Properties systemProperties = System.getProperties();

systemProperties.setProperty("sun.net.client.defaultConnectTimeout","5000");

systemProperties.setProperty("sun.net.client.defaultReadTimeout","5000");


// Insert HttpUrlConnection here ...


// Unset Timeout

System.getProperties().remove("sun.net.client.defaultConnectTimeout");

System.getProperties().remove("sun.net.client.defaultReadTimeout");


Der Timeout in diesem Fall ist in Millisekunden.

PS: Mir ist manchmal ein direkter Rat wichtiger als google sonst würd ich das Forum eher selten benutzen!!

Gruß Scratch

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.