Warning: This API is deprecated and will be removed in a future
version of TensorFlow after
the replacement is stable.
Server
Stay organized with collections
Save and categorize content based on your preferences.
An in-process TensorFlow server, for use in distributed training.
A Server
instance encapsulates a set of devices and a Session
target that can participate in distributed training. A server belongs to a cluster (specified by
a ClusterSpec
), and corresponds to a particular task in a named job. The server can
communicate with any other server in the same cluster. The server will not serve any requests
until start()
is invoked. The server will stop serving requests once stop()
or
close()
is invoked. Be aware that close()
method stops the server if it is
running.
WARNING: A Server
owns resources that must be explicitly freed by
invoking close()
.
Instances of a Server
are thread-safe.
Using example:
import org.tensorflow.Server;
import org.tensorflow.distruntime.ClusterDef;
import org.tensorflow.distruntime.JobDef;
import org.tensorflow.distruntime.ServerDef;
ClusterDef clusterDef = ClusterDef.newBuilder()
.addJob(JobDef.newBuilder()
.setName("worker")
.putTasks(0, "localhost:4321")
.build()
).build();
ServerDef serverDef = ServerDef.newBuilder()
.setCluster(clusterDef)
.setJobName("worker")
.setTaskIndex(0)
.setProtocol("grpc")
.build();
try (Server srv = new Server(serverDef.toByteArray())) {
srv.start();
srv.join();
}
Public Constructors
|
Server(byte[] serverDef)
Constructs a new instance of server.
|
Public Methods
synchronized
void
|
close()
Destroy an in-process TensorFlow server, frees memory.
|
void
|
join()
Blocks until the server has been successfully stopped.
|
synchronized
void
|
start()
Starts an in-process TensorFlow server.
|
synchronized
void
|
stop()
Stops an in-process TensorFlow server.
|
Inherited Methods
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
From interface
java.lang.AutoCloseable
Public Constructors
public
Server
(byte[] serverDef)
Constructs a new instance of server.
Parameters
serverDef |
Server definition specified as a serialized ServerDef
protocol buffer.
|
Public Methods
public
synchronized
void
close
()
Destroy an in-process TensorFlow server, frees memory.
public
void
join
()
Blocks until the server has been successfully stopped.
public
synchronized
void
start
()
Starts an in-process TensorFlow server.
public
synchronized
void
stop
()
Stops an in-process TensorFlow server.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-02-12 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-02-12 UTC."],[],[],null,["# Server\n\npublic final class **Server** \nAn in-process TensorFlow server, for use in distributed training.\n\nA `Server` instance encapsulates a set of devices and a [Session](/api_docs/java/org/tensorflow/Session)\ntarget that can participate in distributed training. A server belongs to a cluster (specified by\na `ClusterSpec`), and corresponds to a particular task in a named job. The server can\ncommunicate with any other server in the same cluster. The server will not serve any requests\nuntil [start()](/api_docs/java/org/tensorflow/Server#start()) is invoked. The server will stop serving requests once [stop()](/api_docs/java/org/tensorflow/Server#stop()) or\n[close()](/api_docs/java/org/tensorflow/Server#close()) is invoked. Be aware that [close()](/api_docs/java/org/tensorflow/Server#close()) method stops the server if it is\nrunning.\n\n**WARNING:** A `Server` owns resources that **must** be explicitly freed by\ninvoking [close()](/api_docs/java/org/tensorflow/Server#close()).\n\nInstances of a `Server` are thread-safe.\n\nUsing example:\n\n import org.tensorflow.Server;\n import org.tensorflow.distruntime.ClusterDef;\n import org.tensorflow.distruntime.JobDef;\n import org.tensorflow.distruntime.ServerDef;\n\n ClusterDef clusterDef = ClusterDef.newBuilder()\n .addJob(JobDef.newBuilder()\n .setName(\"worker\")\n .putTasks(0, \"localhost:4321\")\n .build()\n ).build();\n\n ServerDef serverDef = ServerDef.newBuilder()\n .setCluster(clusterDef)\n .setJobName(\"worker\")\n .setTaskIndex(0)\n .setProtocol(\"grpc\")\n .build();\n\n try (Server srv = new Server(serverDef.toByteArray())) {\n srv.start();\n srv.join();\n }\n \n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Public Constructors\n\n|---|------------------------------------------------------------------------------------------------------------------------|\n| | [Server](/api_docs/java/org/tensorflow/Server#Server(byte[]))(byte\\[\\] serverDef) Constructs a new instance of server. |\n\n### Public Methods\n\n|-------------------|----------------------------------------------------------------------------------------------------------------|\n| synchronized void | [close](/api_docs/java/org/tensorflow/Server#close())() Destroy an in-process TensorFlow server, frees memory. |\n| void | [join](/api_docs/java/org/tensorflow/Server#join())() Blocks until the server has been successfully stopped. |\n| synchronized void | [start](/api_docs/java/org/tensorflow/Server#start())() Starts an in-process TensorFlow server. |\n| synchronized void | [stop](/api_docs/java/org/tensorflow/Server#stop())() Stops an in-process TensorFlow server. |\n\n### Inherited Methods\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.lang.AutoCloseable \n\n|---------------|---------|\n| abstract void | close() |\n\nPublic Constructors\n-------------------\n\n#### public\n**Server**\n(byte\\[\\] serverDef)\n\nConstructs a new instance of server. \n\n##### Parameters\n\n| serverDef | Server definition specified as a serialized [ServerDef](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/tensorflow_server.proto) protocol buffer. |\n|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\nPublic Methods\n--------------\n\n#### public synchronized void\n**close**\n()\n\nDestroy an in-process TensorFlow server, frees memory. \n\n##### Throws\n\n| InterruptedException | |\n|----------------------|---|\n\n#### public void\n**join**\n()\n\nBlocks until the server has been successfully stopped. \n\n#### public synchronized void\n**start**\n()\n\nStarts an in-process TensorFlow server. \n\n#### public synchronized void\n**stop**\n()\n\nStops an in-process TensorFlow server."]]