This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package synchronize; | |
| public class MathClass { | |
| synchronized void printNumbers(int n) throws InterruptedException | |
| { | |
| for (int i=1; i<=n;i++){ | |
| System.out.println(Thread.currentThread().getName() + "::" + i); | |
| Thread.sleep(500); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "runtime" | |
| "fmt" | |
| ) | |
| func main() { | |
| nCPU:=runtime.NumCPU() | |
| runtime.GOMAXPROCS(nCPU) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(string[] args){ | |
| new FixedThreadPoolExecutor(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package taskExecutor; | |
| import java.util.concurrent.TimeUnit; | |
| public class Task implements Runnable { | |
| private String name; | |
| public Task(String name){ | |
| this.name = name; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package taskExecutor; | |
| import java.util.concurrent.Executors; | |
| import java.util.concurrent.ThreadPoolExecutor; | |
| public class FixedThreadPoolExecutor { | |
| public FixedThreadPoolExecutor(){ | |
| ThreadPoolExecutor executor = (ThreadPoolExecutor)Executors.newFixedThreadPool(4); | |
| for(int i=0; i<10;i++){ | |
| Task task = new Task("Task" + i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Retention(RetentionPolicy.RUNTIME) | |
| @Target(ElementType.FIELD) | |
| public @interface myField { | |
| public boolean enabled() default true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Retention(RetentionPolicy.RUNTIME) | |
| @Target(ElementType.METHOD) | |
| public @interface myMethod { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Retention(RetentionPolicy.RUNTIME) | |
| @Target(ElementType.TYPE) | |
| public @interface myType { | |
| public String brokers() default "localhost"; | |
| public boolean _continue() default false; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class threadWithTheaClass extends Thread { | |
| public void run(){ | |
| System.out.println("thread using class"); | |
| } | |
| } | |
| public class main{ | |
| public static void main(string[] args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class annonymousClassUsingThreadClass { | |
| public annonymousClassUsingThreadClass() { | |
| Thread t = new Thread(){ | |
| public void run(){ | |
| System.out.println("anonymous thread"); | |
| } | |
| }; | |
| t.start(); | |
| } | |
| } |
OlderNewer