| @@ -0,0 +1,40 @@ | ||
| 4----------groups | ||
| 1 | ||
| Runner{id=0, timeResult=85.29010359906617, status=ENDRUN} | ||
| Runner{id=1, timeResult=77.69958681569113, status=ENDRUN} | ||
| Runner{id=2, timeResult=29.389307823001044, status=ENDRUN} | ||
| Runner{id=3, timeResult=60.850864548241205, status=ENDRUN} | ||
| Runner{id=4, timeResult=32.45582023207664, status=ENDRUN} | ||
| Runner{id=5, timeResult=62.250292613467415, status=ENDRUN} | ||
| Runner{id=6, timeResult=8.1241297806531, status=ENDRUN} | ||
| Runner{id=7, timeResult=52.36675852800211, status=ENDRUN} | ||
| Runner{id=8, timeResult=51.294361481436624, status=ENDRUN} | ||
| Runner{id=9, timeResult=62.08011859899061, status=ENDRUN} | ||
| 2 | ||
| Runner{id=10, timeResult=7.069119268896307, status=ENDRUN} | ||
| Runner{id=11, timeResult=2.2899283981089646, status=ENDRUN} | ||
| Runner{id=12, timeResult=35.63161002738067, status=ENDRUN} | ||
| Runner{id=13, timeResult=63.933734683177676, status=ENDRUN} | ||
| Runner{id=14, timeResult=40.50293203987947, status=ENDRUN} | ||
| Runner{id=15, timeResult=70.3207823161622, status=ENDRUN} | ||
| Runner{id=16, timeResult=39.20884887257357, status=ENDRUN} | ||
| Runner{id=17, timeResult=47.65551097404527, status=ENDRUN} | ||
| Runner{id=18, timeResult=81.6578578685931, status=ENDRUN} | ||
| Runner{id=19, timeResult=93.00913695221857, status=ENDRUN} | ||
| 3 | ||
| Runner{id=20, timeResult=89.53349296518942, status=ENDRUN} | ||
| Runner{id=21, timeResult=42.128784517751114, status=ENDRUN} | ||
| Runner{id=22, timeResult=34.59804422296083, status=ENDRUN} | ||
| Runner{id=23, timeResult=82.99661773784929, status=ENDRUN} | ||
| Runner{id=24, timeResult=62.66779237394016, status=ENDRUN} | ||
| Runner{id=25, timeResult=80.92338613176864, status=ENDRUN} | ||
| Runner{id=26, timeResult=28.640025551026206, status=ENDRUN} | ||
| Runner{id=27, timeResult=3.4510557252438345, status=ENDRUN} | ||
| Runner{id=28, timeResult=44.62994563245118, status=ENDRUN} | ||
| Runner{id=29, timeResult=80.0299835772257, status=ENDRUN} | ||
| 4 | ||
| Runner{id=30, timeResult=74.12471931394573, status=ENDRUN} | ||
| Runner{id=31, timeResult=44.221786613321015, status=ENDRUN} | ||
| Runner{id=32, timeResult=79.00786260976234, status=ENDRUN} | ||
| Runner{id=33, timeResult=72.2668089063463, status=ENDRUN} | ||
| Runner{id=34, timeResult=50.08842516196812, status=ENDRUN} |
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
| <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false"> | ||
| <output url="file://$MODULE_DIR$/target/classes" /> | ||
| <output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
| <content url="file://$MODULE_DIR$"> | ||
| <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
| <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
| <excludeFolder url="file://$MODULE_DIR$/target" /> | ||
| </content> | ||
| <orderEntry type="inheritedJdk" /> | ||
| <orderEntry type="sourceFolder" forTests="false" /> | ||
| <orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" /> | ||
| <orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.10" level="project" /> | ||
| <orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" /> | ||
| </component> | ||
| </module> |
| @@ -0,0 +1,36 @@ | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>com.levelup</groupId> | ||
| <artifactId>threads</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>threads</name> | ||
| <url>http://maven.apache.org</url> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>3.8.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>1.16.10</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.guava</groupId> | ||
| <artifactId>guava</artifactId> | ||
| <version>19.0</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
| @@ -0,0 +1,56 @@ | ||
| package com.levelup; | ||
|
|
||
|
|
||
| //забег, 10 бегунов. 1 группа - результаты - положил. следуюшая 10 - .... . стутус каждого. трисет. очередь. общая таблица. | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class Championship { | ||
| public static int groupCount; | ||
| public static int runnerAmount = 35; | ||
| public static List<Runner> runnerList = new ArrayList<Runner>(runnerAmount); | ||
|
|
||
|
|
||
| public static void main(String[] args) { | ||
| ThreadGroup groupA = new ThreadGroup("Group A"); | ||
| // Sprint sprint = new Sprint(groupA,"JThread "); | ||
| createRunnerList(); | ||
| // sprint.run(); | ||
| //System.out.println(runnerList.toString()); | ||
|
|
||
| /*for (int i = 0; i < 9; i++) | ||
| new Sprint(groupA, "JThread " + i).start();*/ | ||
|
|
||
| Thread th1 = new Thread(new Sprint(groupA, "JThread ")); | ||
| th1.start(); | ||
| try { | ||
| //sprint.run(); | ||
| Thread.sleep(0); | ||
| } catch (Exception e) { | ||
| System.out.println(e); | ||
| } | ||
|
|
||
|
|
||
| SortedSet<Integer> resultTable = new TreeSet<Integer>(); | ||
| } | ||
|
|
||
|
|
||
| public static List createRunnerList() { | ||
| for (int i = 0; i < runnerAmount; i++) { | ||
| Runner runner = new Runner(i , 0, RunnerStatus.WAITFORRUN); | ||
| runnerList.add(runner); | ||
| //System.out.println(runner.toString()); | ||
| } | ||
| return runnerList; | ||
| } | ||
|
|
||
| public static int groupCounter() { | ||
| if (runnerAmount % 10 == 0) { | ||
| groupCount = runnerAmount / 10; | ||
| } else { | ||
| groupCount = runnerAmount / 10 + 1; | ||
| } | ||
| return groupCount; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,7 @@ | ||
| package com.levelup; | ||
|
|
||
|
|
||
| public interface IRunner { | ||
| Enum status(); | ||
| boolean run(); | ||
| } |
| @@ -0,0 +1,37 @@ | ||
| package com.levelup; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class Runner implements IRunner { | ||
| @Getter | ||
| @Setter | ||
| private int id; | ||
| @Getter | ||
| @Setter | ||
| private double timeResult; | ||
| @Getter | ||
| @Setter | ||
| private Enum status; | ||
|
|
||
| public Enum status() { | ||
| return null; | ||
| } | ||
|
|
||
| public boolean run() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Runner{" + | ||
| "id=" + id + | ||
| ", timeResult=" + timeResult + | ||
| ", status=" + status + | ||
| '}'; | ||
| } | ||
| } |
| @@ -0,0 +1,8 @@ | ||
| package com.levelup; | ||
|
|
||
| /** | ||
| * Created by Admin on 14.10.2016. | ||
| */ | ||
| public enum RunnerStatus { | ||
| ENDRUN, RUN, WAITFORRUN | ||
| } |
| @@ -0,0 +1,39 @@ | ||
| package com.levelup; | ||
|
|
||
| public class Sprint extends Thread { | ||
| Championship championship = new Championship(); | ||
|
|
||
| public Sprint(ThreadGroup group, String name) { | ||
| super(group, name); | ||
| } | ||
|
|
||
| public void run() { | ||
| System.out.println(championship.groupCounter() + "----------groups"); | ||
| for (int i = 0; i < championship.runnerAmount; i++) { | ||
| championship.runnerList.get(i).setStatus(RunnerStatus.RUN); | ||
| } | ||
| for (int i = 0; i < championship.groupCounter(); i++) { | ||
| System.out.println(i + 1); | ||
|
|
||
| if (i == championship.groupCounter()) { | ||
|
|
||
| for (int j = (championship.groupCounter() - 1) * 10 - 1; j < (championship.runnerAmount) - 1; j++) { | ||
| championship.runnerList.get(i * 10 - j).setTimeResult(Math.random() * 100); | ||
| championship.runnerList.get(i * 10 - j).setStatus(RunnerStatus.ENDRUN); | ||
| System.out.println(championship.runnerList.get(i * 10 - j).toString()); | ||
| } | ||
|
|
||
|
|
||
| } else { | ||
| for (int j = 0; j < 10; j++) { | ||
| if ((i * 10 + j) == championship.runnerAmount) { | ||
| break; | ||
| } | ||
| championship.runnerList.get(i * 10 + j).setTimeResult(Math.random() * 100); | ||
| championship.runnerList.get(i * 10 + j).setStatus(RunnerStatus.ENDRUN); | ||
| System.out.println(championship.runnerList.get(i * 10 + j).toString()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,38 @@ | ||
| package com.levelup; | ||
|
|
||
| import junit.framework.Test; | ||
| import junit.framework.TestCase; | ||
| import junit.framework.TestSuite; | ||
|
|
||
| /** | ||
| * Unit test for simple App. | ||
| */ | ||
| public class AppTest | ||
| extends TestCase | ||
| { | ||
| /** | ||
| * Create the test case | ||
| * | ||
| * @param testName name of the test case | ||
| */ | ||
| public AppTest( String testName ) | ||
| { | ||
| super( testName ); | ||
| } | ||
|
|
||
| /** | ||
| * @return the suite of tests being tested | ||
| */ | ||
| public static Test suite() | ||
| { | ||
| return new TestSuite( AppTest.class ); | ||
| } | ||
|
|
||
| /** | ||
| * Rigourous Test :-) | ||
| */ | ||
| public void testApp() | ||
| { | ||
| assertTrue( true ); | ||
| } | ||
| } |