Skip to content

Commit f5507e9

Browse files
committed
Add defensive sync around service start and init
1 parent dd375f8 commit f5507e9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/org/apposed/appose/Service.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ public Service debug(Consumer<String> debugListener) {
131131
*
132132
* @param script The script code to execute during worker initialization.
133133
* @return This service object, for chaining method calls.
134+
* @throws IllegalStateException If the service has already started.
134135
*/
135-
public Service init(String script) {
136+
public synchronized Service init(String script) {
137+
if (process != null) throw new IllegalStateException("Service already started");
136138
this.initScript = script;
137139
return this;
138140
}
@@ -143,7 +145,7 @@ public Service init(String script) {
143145
* @return This service object, for chaining method calls (typically with {@link #task}).
144146
* @throws IOException If the process fails to execute; see {@link ProcessBuilder#start()}.
145147
*/
146-
public Service start() throws IOException {
148+
public synchronized Service start() throws IOException {
147149
if (process != null) {
148150
// Already started.
149151
return this;

0 commit comments

Comments
 (0)