Хотя Андрей связался с достойным решением, у него меньше кода, но он нашел хорошее решение:
Пример кода:
//
// setting a connection timeout (fifteen seconds on the example)
//
$client = new SoapClient($wsdl, array("connection_timeout" => 15));
И есть также контекст потока, если вам нужно более детальное управление HTTP. См. Параметр stream_context
для new SoapClient()
Документов sup> . Под поверхностью SoapClient
используются транспорты HTTP и SSL.
The object is not garbage collected. This is know as "Object resurrection".
You must be careful with that, once the finalizer is called the gc won't call it again, on some enviroments like .NET you can re-register the finalizer but i'm not sure about java
If you absolutely must resurrect objects, this JavaWorld article suggests creating a fresh instance rather than resurrecting the instance being finalized because if the instance being finalized becomes eligible for collection again it will simply be collected (the finalizer won't be run again).
This kind of thing is the reason why the use of finalize()
is generally discouraged.
Because Java is a safe language and platform, the memory is not freed. Also associated PhantomReference
s will not be enqueued upon their ReferenceQueue
s. The VM will only ever call finalize
on an object once. There's a nice state diagram in the JVM Spec.
Typically if you do use a finaliser, you should leave the declaration as @Override protected void finalize() throws Throwable
, so as not to disturb the API. Even better use a guarded finaliser, as in Effective Java 1st Ed.
This particular trick hit the headlines (of the San Jose Mercury, anyway) when a group at Princeton used it to construct a custom ClassLoader
from untrusted code. Although the spec has been slightly tightened (the Object
constructor has to finish executing normally before the finaliser can be called - specified in J2SE 5.0, implemented in Java SE 6), this still remains a problem area. If you are designing an API, make sure sensitive classes cannot be subclasses and save yourself much grief.
Метод finalize ()
может быть вызван явно для экземпляра foo
, либо он может быть вызван сборщиком мусора, когда он пытается вернуть память, занятая этим объектом.
Если bar
является допустимым экземпляром, он устанавливает поле REFERENCE
в экземпляр foo
. С точки зрения сборщика мусора это увеличивает счетчик ссылок foo
.
Если исключение выбрасывается внутри метода finalize ()
(например, такого как NullPointerException
из-за того, что bar
имеет значение null
), тогда процесс завершения просто завершается.
NB Как уже отмечали другие ... вашего примера определенно следует избегать.