Skip to content
Snippets Groups Projects
Commit 6e7be183 authored by Sven Steddin's avatar Sven Steddin
Browse files

Erweiterung Beispielprojekte

parent b3149d9d
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ThreadsMonitor1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
package inf3;
public class Ausgabe {
//synchronized static void SchreibeZeile (char c) {
static void SchreibeZeile (char c) {
for (int ii=0; ii< 20; ii++) {
System.out.print(c + " ");
//Warteschleife:
for (int ll=0; ll< 1000000; ll++) {
Double kk = Math.sqrt(ll);
}
}
System.out.println();
}
}
package inf3;
public class Thread_TextAusgabe extends Thread {
char c;
Thread_TextAusgabe (char c) {
this.c = c;
}
public void run() {
for (int ii=0; ii< 5; ii++) {
Ausgabe.SchreibeZeile(c);
}
}
}
/** Programm zur Demonstration der Threadsynchronisation
* durch den Einsatz eines Monitors: Zwei Threads sollen
* jeweils 10 mal die im Konstruktor bergebene Ziffer in eine
* Zeile schreiben. Erst wenn die Methode SchreibeZeile() gegen
* Unterbrechungen gesperrt wird, indem sie mit synchronized er-
* weitert wird, erhlt man die gewnschte gleichmige Ausgabe
* der Zahlenwerte.
*
* @author stedS
* @version 1.0 (2016-01-12)
*/
package inf3;
public class ThreadsMonitor1 {
char c;
public static void main(String[] args) {
Thread_TextAusgabe th1 = new Thread_TextAusgabe('1');
Thread_TextAusgabe th2 = new Thread_TextAusgabe('2');
th1.start();
th2.start();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment