Java Program to Use Exceptions with Thread
Exceptions are the events that occur due to the programmer error or machine error which causes a disturbance in the normal flow of execution of the program. When a method encounters an abnormal condition that it can not handle, an exception is thrown as an exception statement. Exceptions are caught by handlers(here catch block). Exceptions are caught by handlers positioned along with the thread’s method invocation stack. If the calling method is not prepared to catch the exception, it throws the exception up to its calling method and so on. So in the java program exception handlers should be positioned strategically, so the program catches all the exception from which the program want to recover.
Lifecycle of a thread: The class implements a Thread class or Runnable interface then the extended class has start() method run the thread, sleep() methods cause the currently executing thread to sleep for the specified number of milliseconds, and many more.
Prior to discussing the approaches, state. transactions of thread should be known to further deal with exceptions for better understanding. A thread in Java at any point in time exists in any one of the following states. A thread lies only in one of the shown states at any instant:
- New
- Runnable
- Blocked
- Waiting
- Timed Waiting
- Terminated
1. A class name RunnableThread implements the Runnable interface which gives the run( ) method executed by the thread. The object of this class is now runnable
2. The Thread constructor is used to create an object of RunnableThread class by passing the runnable object as a parameter.
3. The start() method is invoked on the Thread object as it returns immediately once a thread has been spawned.
4. The thread ends when the run( ) method ends which is to be normal termination or caught exception.
5. Now in order to create a new thread
runner = new Thread(this,threadName) ;
6. In order to start the new thread.
7. public void run( ) is an overridable method used to display the information of a particular thread.
8. Thread.currentThread().sleep(2000) is used to deactivate the thread until the next thread started execution or used to delay the current thread.
Uncaught exception handler will be used to demonstrate the use of exception with thread. It is a specific interface provided by Java to handle exception in the thread run method.
There are two methods to create a thread:
- Extend the thread Class (java.lang.thread)
- Implement Runnable Interface (java.lang.thread)
1. Exception and Exception handling with threads
Here, a new thread is created in the class which is extending the thread class in which run() method is overridden. This invokes the entry point of the new thread created in the class which was extending the thread class. Further, start() method is used to start and run the thread in the program.
Java lang thread run error
Ваш браузер устарел, и поэтому некоторые важные функции этого сайта могут не работать. Пожалуйста, обновитесь то более современного браузера. 🙁
Ошибка при старте сервера
Areksei
02:56:42] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.NoClassDefFoundError: Could not initialize class Reflector
at net.minecraft.crash.CrashReport.func_71504_g(CrashReport.java:163) ~[b.class:?]
at net.minecraft.crash.CrashReport.(CrashReport.java:55) ~[b.class:?]
at net.minecraft.crash.CrashReport.func_85055_a(CrashReport.java:442) ~[b.class:?]
at net.minecraft.world.World.(World.java:196) ~[ahb.class:?]
at net.minecraft.world.WorldServer.(WorldServer.java:158) ~[mt.class:?]
at net.minecraft.server.MinecraftServer.func_71247_a(MinecraftServer.java:367) ~[MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:336) ~[lt.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:631) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_161] [02:56:42] [Server thread/INFO]: Applying holder lookups
[02:56:42] [Server thread/INFO]: Holder lookups applied [02:56:42] [Server thread/INFO]: The state engine was in incorrect state SERVER_STARTING and forced into state SERVER_STOPPED. Errors may have been discarded.egg2003
ТруЪ Олдфаги-с
Areksei
Father
Ru Beta — Сервер на версии 1.7.3 Бета
Areksei
Areksei
Sverinn
Звание: Где-то рядом с нами
Совмещаю лень и продуктивность
Areksei
ZilkPlayz Зилк
C:\Users\(Пользователь)\Desktop\Новая папка (5)\serverCD>java -Xms512M -Xmx1536M -XX:MaxPermSize-128M -jar craftbukkit-1.12.2.jar
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize-128M; support was removed in 8.0
Loading libraries, please wait.
[10:27:08 INFO]: Starting minecraft server version 1.12.2
[10:27:08 INFO]: Loading properties
[10:27:08 INFO]: Default game type: SURVIVAL
[10:27:08 ERROR]: Encountered an unexpected exception
java.net.UnknownHostException: mc.craftdolphins.ru
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[?:1.8.0_221]
at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source) ~[?:1.8.0_221]
at java.net.InetAddress.getAddressesFromNameService(Unknown Source) ~[?:1.8.0_221]
at java.net.InetAddress.getAllByName0(Unknown Source) ~[?:1.8.0_221]
at java.net.InetAddress.getAllByName(Unknown Source) ~[?:1.8.0_221]
at java.net.InetAddress.getAllByName(Unknown Source) ~[?:1.8.0_221]
at java.net.InetAddress.getByName(Unknown Source) ~[?:1.8.0_221]
at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:166) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:522) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_221][10:27:08 ERROR]: This crash report has been saved to: C:\Users\эфЁхщ\Desktop\ютр яряър (5)\serverCD\.\crash-reports\crash-2019-10-29_10.27.08-server.txt
[10:27:08 INFO]: Stopping server
ВОТ МОЙ КРАШЛОГ ЧТО ЭТО.
MrKirill1232
AnYEA
WARNING: coremods are present:
Do not report to Forge! (If you haven’t disabled the FoamFix coremod, try disabling it in the config! Note that this bit of text will still appear.) (foamfix-0.10.10-1.12.2.jar)
ObfuscatePlugin (obfuscate-0.2.6-1.12.2.jar)
McLib core mod (mclib-1.0.4-1.12.2.jar)
PerformantLoadingPlugin (performant_1.12.2_1.7.jar)
Contact their authors BEFORE contacting forge
// I bet Cylons wouldn’t have this problem.
Time: 31.01.20 13:50
Description: Exception in server tick loop
java.net.UnknownHostException: 8805353535
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java
:176)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:486)
at java.lang.Thread.run(Unknown Source)
— System Details —
Details:
Minecraft Version: 1.12.2
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 346265688 bytes (330 MB) / 1200578560 bytes (1144 MB) up to 2112618496 bytes (2014 MB)
JVM Flags: 2 total; -Xincgc -Xmx2G
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.42 Powered by Forge 14.23.5.2847 24 mods loaded, 23 mods active
States: ‘U’ = Unloaded ‘L’ = Loaded ‘C’ = Constructed ‘H’ = Pre-initialized ‘I’ = Initialized ‘J’ = Post-initialized ‘A’ = Available ‘D’ = Disabled ‘E’ = Errored
| State | ID | Version | Source | Signature |
|:—— |:—————— |:——————— |:————————————— |:——— |
| LCH | minecraft | 1.12.2 | minecraft.jar | None |
| LCH | mcp | 9.42 | minecraft.jar | None |
| LCH | FML | 8.0.99.99 | forge-1.12.2-14.23.5.2847-universal.jar | None |
| LCH | forge | 14.23.5.2847 | forge-1.12.2-14.23.5.2847-universal.jar | None |
| LCH | foamfixcore | 7.7.4 | minecraft.jar | None |
| LCH | obfuscate | 0.2.6 | minecraft.jar | None |
| LCH | school | 1.0 | Another_School_Mod_1.12.2.jar | None |
| LCH | bibliocraft | 2.4.5 | BiblioCraftv2.4.5MC1.12.2.jar | None |
| LCH | chineseworkshop | 1.2.5 | ChineseWorkshop_1.12.2_1.2.5.jar | None |
| LCH | colorfularmor | 1.1 | colorfularmor_1.12.2_1.1.jar | None |
| LCH | props | 2.6.3 | Decocraft-2.6.3_1.12.2.jar | None |
| LCH | mclib | 1.0.4 | mclib-1.0.4-1.12.2.jar | None |
| LCH | emoticons | 0.4 | emoticons-0.4-1.12.2-dist.jar | None |
| LCH | foamfix | 0.10.10-1.12.2 | foamfix-0.10.10-1.12.2.jar | None |
| LCH | cfm | 6.3.0 | furniture_6.3.0_1.12.2.jar | None |
| LCH | gymcraft_1122 | 1.12.2 | GymCraft1.12.2.jar | None |
| LCH | inventorysorter | 1.12.0+49 | inventorysorter_1.12.2_1.12.049.jar | None |
| LCH | pathundergates | 1.12.2-1.0.0-release | pathundergates_1.12.2_1.0.0_release.jar | None |
| LCH | performant | 1.12.2-1.4 | performant_1.12.2_1.7.jar | None |
| LCH | pointless_tech_two | 2 | Pointless_Tech2_1.12.2.jar | None |
| LCH | pointlesstech | Version 1 | Pointless_Tech_V1_1.12.2.jar | None |
| LCH | vehicle | 0.41.0 | vehicle-mod-0.41.0-1.12.2.jar | None |
| LCH | xlfoodmod | 1.12.2-1.9.2 | XL_Food_Mod_1.12.2_1.9.2.jar | None |
| UD | mclib_core | 1.0.4 | minecraft.jar | None |
Loaded coremods (and transformers):
Do not report to Forge! (If you haven’t disabled the FoamFix coremod, try disabling it in the config! Note that this bit of text will still appear.) (foamfix-0.10.10-1.12.2.jar)
pl.asie.foamfix.coremod.FoamFixTransformer
ObfuscatePlugin (obfuscate-0.2.6-1.12.2.jar)
com.mrcrayfish.obfuscate.asm.ObfuscateTransformer
McLib core mod (mclib-1.0.4-1.12.2.jar)
mchorse.mclib.core.McLibCMClassTransformer
PerformantLoadingPlugin (performant_1.12.2_1.7.jar)
Profiler Position: N/A (disabled)
Is Modded: Definitely; Server brand changed to ‘fml,forge’
Type: Dedicated Server (map_server.txt) что делать?