Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci_java/concurrent/data/Main.java
169689 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.
4
// TraaS module
5
// Copyright (C) 2013-2017 Dresden University of Technology
6
// This program and the accompanying materials are made available under the
7
// terms of the Eclipse Public License 2.0 which is available at
8
// https://www.eclipse.org/legal/epl-2.0/
9
// This Source Code may also be made available under the following Secondary
10
// Licenses when the conditions for such availability set forth in the Eclipse
11
// Public License 2.0 are satisfied: GNU General Public License, version 2
12
// or later which is available at
13
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15
/****************************************************************************/
16
/// @file Main.java
17
/// @author Mario Krumnow
18
/// @author Jakob Erdmann
19
/// @date 2013
20
///
21
//
22
/****************************************************************************/
23
import java.util.ArrayList;
24
import java.util.List;
25
26
import org.eclipse.sumo.libtraci.*;
27
28
class Runner implements Runnable {
29
public void run() {
30
System.out.println("Thread started");
31
for (int i = 0; i < 100; i++) {
32
Simulation.step();
33
double timeSeconds = Simulation.getTime();
34
int tlsPhase = TrafficLight.getPhase("gneJ1");
35
String tlsPhaseName = TrafficLight.getPhaseName("gneJ1");
36
TraCIVehicleDataVector vehData = InductionLoop.getVehicleData("loop1");
37
}
38
}
39
}
40
41
public class Main {
42
public static void main(String[] args) {
43
Simulation.preloadLibraries();
44
String sumo_bin = "sumo";
45
String config_file = "data/config.sumocfg";
46
if (args.length > 0) {
47
sumo_bin = args[0];
48
}
49
if (args.length > 1) {
50
config_file = args[1];
51
}
52
53
Simulation.start(new StringVector(new String[] {sumo_bin,
54
"-c", config_file,
55
"--start",
56
"--step-length", "0.1"
57
}));
58
List<Thread> threads = new ArrayList<Thread>();
59
for (int i = 0; i < 100; i++) {
60
threads.add(new Thread(new Runner()));
61
threads.get(i).start();
62
}
63
try {
64
for (int i = 0; i < 100; i++) {
65
threads.get(i).join();
66
}
67
} catch (InterruptedException e) {}
68
Simulation.close();
69
}
70
}
71
72