Skip to content

Commit e072c8c

Browse files
committed
defer updating from web until after thread starts
1 parent ead5a8e commit e072c8c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/main/java/cz/mallat/uasparser/OnlineUpdater.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public OnlineUpdater(UASparser parser, String cacheDir, long interval, TimeUnit
7979
}
8080

8181
/**
82-
* Initialize the parser and start update thread
82+
* Initialize the parser with cached data. Falls back to vendored copy if no cache is available.
8383
*/
8484
public void init() {
8585

@@ -94,13 +94,10 @@ public void init() {
9494
}
9595
}
9696

97-
// try online update
98-
if (!update()) {
99-
try {
100-
// fallback to vendored copy
101-
parser.loadDataFromFile(getVendoredInputStream());
102-
} catch (IOException e) {
103-
}
97+
try {
98+
// fall back to vendored copy so we don't block on startup
99+
parser.loadDataFromFile(getVendoredInputStream());
100+
} catch (IOException e) {
104101
}
105102
}
106103

@@ -142,12 +139,12 @@ public boolean update() {
142139
@Override
143140
public void run() {
144141
while (true) {
142+
update();
145143
try {
146144
Thread.sleep(updateInterval);
147145
} catch (InterruptedException e) {
148146
return;
149147
}
150-
update();
151148
}
152149
}
153150

0 commit comments

Comments
 (0)