Path: blob/main/tests/complex/traci_java/concurrent/data/Main.java
169689 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.3// TraaS module4// Copyright (C) 2013-2017 Dresden University of Technology5// This program and the accompanying materials are made available under the6// terms of the Eclipse Public License 2.0 which is available at7// https://www.eclipse.org/legal/epl-2.0/8// This Source Code may also be made available under the following Secondary9// Licenses when the conditions for such availability set forth in the Eclipse10// Public License 2.0 are satisfied: GNU General Public License, version 211// or later which is available at12// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html13// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later14/****************************************************************************/15/// @file Main.java16/// @author Mario Krumnow17/// @author Jakob Erdmann18/// @date 201319///20//21/****************************************************************************/22import java.util.ArrayList;23import java.util.List;2425import org.eclipse.sumo.libtraci.*;2627class Runner implements Runnable {28public void run() {29System.out.println("Thread started");30for (int i = 0; i < 100; i++) {31Simulation.step();32double timeSeconds = Simulation.getTime();33int tlsPhase = TrafficLight.getPhase("gneJ1");34String tlsPhaseName = TrafficLight.getPhaseName("gneJ1");35TraCIVehicleDataVector vehData = InductionLoop.getVehicleData("loop1");36}37}38}3940public class Main {41public static void main(String[] args) {42Simulation.preloadLibraries();43String sumo_bin = "sumo";44String config_file = "data/config.sumocfg";45if (args.length > 0) {46sumo_bin = args[0];47}48if (args.length > 1) {49config_file = args[1];50}5152Simulation.start(new StringVector(new String[] {sumo_bin,53"-c", config_file,54"--start",55"--step-length", "0.1"56}));57List<Thread> threads = new ArrayList<Thread>();58for (int i = 0; i < 100; i++) {59threads.add(new Thread(new Runner()));60threads.get(i).start();61}62try {63for (int i = 0; i < 100; i++) {64threads.get(i).join();65}66} catch (InterruptedException e) {}67Simulation.close();68}69}707172