Initial commit
This commit is contained in:
29
example_src/.gitignore
vendored
Normal file
29
example_src/.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
8
example_src/.idea/.gitignore
generated
vendored
Normal file
8
example_src/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
5
example_src/.idea/misc.xml
generated
Normal file
5
example_src/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
example_src/.idea/modules.xml
generated
Normal file
8
example_src/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Network_Communication.iml" filepath="$PROJECT_DIR$/Network_Communication.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
4
example_src/.idea/vcs.xml
generated
Normal file
4
example_src/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
</project>
|
||||
11
example_src/Network_Communication.iml
Normal file
11
example_src/Network_Communication.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
24
example_src/src/Bus.java
Normal file
24
example_src/src/Bus.java
Normal file
@@ -0,0 +1,24 @@
|
||||
public class Bus implements MyPay,MyInterface2 {
|
||||
|
||||
public void payMoney() {
|
||||
System.out.println("Bus pay money:2元");
|
||||
|
||||
}
|
||||
public void myPrint() {
|
||||
System.out.println("my bus print");
|
||||
|
||||
}
|
||||
public void myMethod() {
|
||||
System.out.println("aggdksjal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MyInter1Fun() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MyInter2Fun() {
|
||||
|
||||
}
|
||||
}
|
||||
18
example_src/src/MyDemo1.java
Normal file
18
example_src/src/MyDemo1.java
Normal file
@@ -0,0 +1,18 @@
|
||||
class MyClass1{
|
||||
int a1;
|
||||
int a2;
|
||||
void myPrint(){
|
||||
System.out.println("a1 = " + a1);
|
||||
}
|
||||
}
|
||||
class MyClass2 {
|
||||
int a3;
|
||||
void myPrint(){
|
||||
System.out.println("a3 = " + a3);
|
||||
}
|
||||
}
|
||||
public class MyDemo1 extends MyClass1{
|
||||
|
||||
|
||||
|
||||
}
|
||||
3
example_src/src/MyInterface2.java
Normal file
3
example_src/src/MyInterface2.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public interface MyInterface2 {
|
||||
public void myMethod();
|
||||
}
|
||||
13
example_src/src/MyPay.java
Normal file
13
example_src/src/MyPay.java
Normal file
@@ -0,0 +1,13 @@
|
||||
interface MyInter1{
|
||||
void MyInter1Fun();
|
||||
}
|
||||
interface MyInter2{
|
||||
void MyInter2Fun();
|
||||
|
||||
}
|
||||
public interface MyPay extends MyInter1, MyInter2 {
|
||||
// int x=9;
|
||||
void payMoney();
|
||||
void myPrint();
|
||||
|
||||
}
|
||||
23
example_src/src/MyTest1.java
Normal file
23
example_src/src/MyTest1.java
Normal file
@@ -0,0 +1,23 @@
|
||||
public class MyTest1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a=0;
|
||||
int y=100;
|
||||
int z;
|
||||
try{
|
||||
z=y/a;
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("ArithmeticException");
|
||||
z=Integer.MAX_VALUE;
|
||||
System.out.println(z);
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
System.out.println("Exception");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
32
example_src/src/Test1.java
Normal file
32
example_src/src/Test1.java
Normal file
@@ -0,0 +1,32 @@
|
||||
public class Test1 implements Runnable {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
System.out.println("Hello World");
|
||||
Test1 t = new Test1();
|
||||
Thread th1=new Thread(t);
|
||||
th1.setName("Thread1");
|
||||
//th1.run();
|
||||
th1.start();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Thread.sleep(1000);
|
||||
System.out.println("in main");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("nantongdaxue");
|
||||
System.out.println(Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
14
example_src/src/Test2.java
Normal file
14
example_src/src/Test2.java
Normal file
@@ -0,0 +1,14 @@
|
||||
public class Test2 {
|
||||
public static void main(String[] args) {
|
||||
int a = 0;
|
||||
int y;
|
||||
try{
|
||||
y=3/a;
|
||||
}catch(ArithmeticException e){
|
||||
System.out.println("ArithmeticException");
|
||||
y=Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
39
example_src/src/Test3.java
Normal file
39
example_src/src/Test3.java
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
class MyThread extends Thread{
|
||||
public void run(){
|
||||
for(int i=0;i<10;i++){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}catch(InterruptedException e){
|
||||
System.out.println("InterruptedException");
|
||||
}
|
||||
|
||||
System.out.println("in myThread:"+Thread.currentThread().getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Test3 {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
MyThread t1=new MyThread();
|
||||
t1.setName("t1");
|
||||
t1.start();
|
||||
|
||||
MyThread t2=new MyThread();
|
||||
t2.setName("t2");
|
||||
t2.start();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Thread.sleep(1000);
|
||||
System.out.println("in main:"+Thread.currentThread().getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
21
example_src/src/abc/C1.java
Normal file
21
example_src/src/abc/C1.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package abc;
|
||||
|
||||
public class C1 extends Thread{
|
||||
private char ch;
|
||||
private PrintCH pc;
|
||||
|
||||
public C1(char ch, PrintCH pc) {
|
||||
this.ch = ch; this.pc=pc;
|
||||
}
|
||||
public void run(){
|
||||
pc.print(ch);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
PrintCH pc1=new PrintCH();
|
||||
PrintCH pc2=new PrintCH();
|
||||
C1 t1=new C1('A',pc2);
|
||||
C1 t2=new C1('B',pc2);
|
||||
t1.start();
|
||||
t2.start();
|
||||
}
|
||||
}
|
||||
14
example_src/src/abc/PrintCH.java
Normal file
14
example_src/src/abc/PrintCH.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package abc;
|
||||
|
||||
public class PrintCH {
|
||||
public synchronized void print(char c){
|
||||
for(int i=0;i<4;i++){
|
||||
System.out.print(c);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
example_src/src/hk1/hk1.iml
Normal file
11
example_src/src/hk1/hk1.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
18
example_src/src/hk1/src/demo1/MainTest.java
Normal file
18
example_src/src/hk1/src/demo1/MainTest.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package demo1;
|
||||
|
||||
public class MainTest {
|
||||
public static void main(String[] args) {
|
||||
MyThread1 t1 = new MyThread1();
|
||||
Thread myt1 = new Thread(t1);
|
||||
myt1.start();
|
||||
|
||||
|
||||
MyThread2 t2 = new MyThread2();
|
||||
t2.start();
|
||||
|
||||
System.out.println("this is a main function");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
19
example_src/src/hk1/src/demo1/MyThread1.java
Normal file
19
example_src/src/hk1/src/demo1/MyThread1.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package demo1;
|
||||
|
||||
public class MyThread1 implements Runnable {
|
||||
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println("this is a car");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
16
example_src/src/hk1/src/demo1/MyThread2.java
Normal file
16
example_src/src/hk1/src/demo1/MyThread2.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package demo1;
|
||||
|
||||
public class MyThread2 extends Thread {
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println("this is a bus");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
11
example_src/src/hk2/hk2.iml
Normal file
11
example_src/src/hk2/hk2.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
5
example_src/src/hk2/src/Main.java
Normal file
5
example_src/src/hk2/src/Main.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
22
example_src/src/pk1/MyTest.java
Normal file
22
example_src/src/pk1/MyTest.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package pk1;
|
||||
public class MyTest extends Thread{
|
||||
private char ch;
|
||||
private PrintCH2 myprint;
|
||||
public MyTest(char ch, PrintCH2 myprint){
|
||||
this.ch = ch;
|
||||
this.myprint = myprint;
|
||||
}
|
||||
public void run(){
|
||||
synchronized(myprint){
|
||||
myprint.print(ch);
|
||||
}
|
||||
myprint.print(ch);
|
||||
}
|
||||
public static void main(String[] args){
|
||||
PrintCH2 printch2 = new PrintCH2();
|
||||
MyTest t1 = new MyTest('A', myprint);
|
||||
MyTest t2 = new MyTest('B', myprint);
|
||||
t1.start();
|
||||
t2.start();
|
||||
}
|
||||
}
|
||||
49
example_src/src/pk1/pk2/MyThread1.java
Normal file
49
example_src/src/pk1/pk2/MyThread1.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package pk1.pk2;
|
||||
class Thread3 implements Runnable {
|
||||
public void run(){
|
||||
System.out.println("in thread3");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
class MyThread2 extends Thread {
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("in MyThread2"+Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class MyThread1 {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
MyThread2 t = new MyThread2();
|
||||
t.setName("Thread2");
|
||||
t.start();
|
||||
Thread t2 = new Thread(t);
|
||||
t2.setName("Thread3");
|
||||
t2.start();
|
||||
System.out.println(t2.isAlive());
|
||||
System.out.println(t.isAlive());
|
||||
|
||||
Thread3 th3 = new Thread3();
|
||||
Thread myth3 = new Thread(th3);
|
||||
myth3.setName("MyThread3");
|
||||
myth3.start();
|
||||
|
||||
// Thread myth6 = new Thread("aba");
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Thread.sleep(1000);
|
||||
System.out.println("nantongdaxue");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user