SingltonJAVA
This commit is contained in:
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/SingletonClasses.iml" filepath="$PROJECT_DIR$/SingletonClasses.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package SingletonClasses;
|
||||
|
||||
public class LogManagement {
|
||||
|
||||
// First we create an instance of the class
|
||||
private static LogManagement logM;
|
||||
|
||||
// Second, we create a PRIVATE constructor (PRIVATE TO AVOID INSTANTIATION)
|
||||
private LogManagement() {
|
||||
|
||||
}
|
||||
|
||||
// We create public method to access the one and ONLY instance
|
||||
public static LogManagement FuncLog() {
|
||||
if (logM == null) {
|
||||
synchronized (LogManagement.class) {
|
||||
if (logM == null) {
|
||||
logM = new LogManagement();
|
||||
}
|
||||
}
|
||||
}
|
||||
return logM;
|
||||
}
|
||||
|
||||
public void Logs() {
|
||||
System.out.println("Detailed logs on the way");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package SingletonClasses;
|
||||
|
||||
/**
|
||||
* LogReader
|
||||
*/
|
||||
public class LogReading {
|
||||
public static void main(String[] args) {
|
||||
LogManagement.FuncLog().Logs();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package SingletonClasses;
|
||||
|
||||
public class MultiThreads {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
Runnable tast = () -> {
|
||||
LogManagement.FuncLog().Logs();
|
||||
};
|
||||
Thread thread1 = new Thread(tast);
|
||||
Thread thread2 = new Thread(tast);
|
||||
Thread thread3 = new Thread(tast);
|
||||
Thread thread4 = new Thread(tast);
|
||||
Thread thread5 = new Thread(tast);
|
||||
Thread thread6 = new Thread(tast);
|
||||
|
||||
thread1.start();
|
||||
thread2.start();
|
||||
thread3.start();
|
||||
thread4.start();
|
||||
thread5.start();
|
||||
thread6.start();
|
||||
try{
|
||||
|
||||
thread1.join();
|
||||
thread2.join();
|
||||
thread3.join();
|
||||
thread4.join();
|
||||
thread5.join();
|
||||
thread6.join();
|
||||
}catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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$" isTestSource="false" packagePrefix="SingletonClasses" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/SingletonClasses.iml" filepath="$PROJECT_DIR$/SingletonClasses.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+11
@@ -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$" isTestSource="false" packagePrefix="SingletonClasses" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user