Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a6bfff

Browse files
committed
Merge pull request pires#116 from valens254/master
Only one command can write and read a data in one time.
2 parents 780e1fe + 8d94651 commit 7a6bfff

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/main/java/com/github/pires/obd/commands/ObdCommand.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ public ObdCommand(ObdCommand other) {
7272
*/
7373
public void run(InputStream in, OutputStream out) throws IOException,
7474
InterruptedException {
75-
start = System.currentTimeMillis();
76-
sendCommand(out);
77-
readResult(in);
78-
end = System.currentTimeMillis();
75+
synchronized (ObdCommand.class) {//Only one command can write and read a data in one time.
76+
start = System.currentTimeMillis();
77+
sendCommand(out);
78+
readResult(in);
79+
end = System.currentTimeMillis();
80+
}
7981
}
8082

8183
/**
@@ -351,4 +353,19 @@ public final String getCommandPID() {
351353
return cmd.substring(3);
352354
}
353355

356+
@Override
357+
public boolean equals(Object o) {
358+
if (this == o) return true;
359+
if (o == null || getClass() != o.getClass()) return false;
360+
361+
ObdCommand that = (ObdCommand) o;
362+
363+
return cmd != null ? cmd.equals(that.cmd) : that.cmd == null;
364+
}
365+
366+
@Override
367+
public int hashCode() {
368+
return cmd != null ? cmd.hashCode() : 0;
369+
}
370+
354371
}

0 commit comments

Comments
 (0)