'Back-End/Java_1'에 해당되는 글 48건

donaricano-btn

Life cycle of a thread

- According to sun, there is only 4 states, new, runnable, non-runnable and terminated

- but this post I referred consist of 5 states to better understand the threads

1. New

- The thread is in new state 

- If you create an instance of Thread class 

2. Runnable

- The thread is in runnable state after invocation of start()

- the thread scheduler has not selected it to be the running thread

- sleep done, I/O complete, lock available, resume, notify

3. Running

- The thread is in running state

- The thread scheduler has selected it

4. Non-Runnable(Blocked)

- This is the state when the thread is sill alive

- it is currently not eligible to run

- sleep, block on I/O, wait for lock, suspend, wait

5. Terminated

- Dead state when its run() method exits


'Back-End > Java_1' 카테고리의 다른 글

[Java] Thread Scheduler  (0) 2016.10.07
[Java] Creating thread  (0) 2016.10.05
[Java] Multithreading in java  (0) 2016.10.05
[Java] Call by value  (0) 2016.09.13
[Java] Encapsulation  (0) 2016.09.12
블로그 이미지

리딩리드

,
donaricano-btn

Multithreading in java


1. Advantage of Java Multithreading

- It doesn't block the user because threads are independent and you can perform multiple operations at same time

- You can perform many operations together so it saves time

- Threads are independent so it doesn't affect other threads if exception occur in a single thread


2. MultiTasking

- Multitasking is a process of executing multiple tasks simultaneously

- We use it to utilize the CPU

- Multitasking can be achieved by two ways

1) Process-based Multitasking(Multiprocessing)

2) Thread-based Multitasking(Multithreading)


1) Process-based Multitasking(Multiprocessing)

- Each process have its own address in memory i.e. each process allocates separate memory area

- Process is heavyweight

- Cost of communication between the process is high

- Switching from one process to another require some time for saving and loading registers, memory maps...

2) Thread-based Multitasking(Multithreading)

- Threads share the same address space

- Thread is lightweight

- Cost of communication between the thread is low


3. Thread

- A thread is a lightweight sub process

- smallest unit of processing

- Threads are independent, if there occurs exception in one thread, it doesn't affect other threads

- It shares a common memory area

- Thread is executed inside the process

- There can be multiple processes inside the OS and One process can have multiple threads

- At a time one thread is executed only


'Back-End > Java_1' 카테고리의 다른 글

[Java] Creating thread  (0) 2016.10.05
[Java] Life cycle of a thread  (0) 2016.10.05
[Java] Call by value  (0) 2016.09.13
[Java] Encapsulation  (0) 2016.09.12
[Java] Package  (0) 2016.09.12
블로그 이미지

리딩리드

,
donaricano-btn

Call by value

- There is only call by value in java, not call by reference


1. Example


50

50

- The value of data is not changed

2. Another Example

 

- If we pass object in place of any primitive value, original value will be changed

- This case we are passing object as a value



'Back-End > Java_1' 카테고리의 다른 글

[Java] Life cycle of a thread  (0) 2016.10.05
[Java] Multithreading in java  (0) 2016.10.05
[Java] Encapsulation  (0) 2016.09.12
[Java] Package  (0) 2016.09.12
[Java] Interface  (0) 2016.09.12
블로그 이미지

리딩리드

,
donaricano-btn

Encapsulation

- Encapsulation is a process of wrapping code and data together into a single unit

- We can create a fully encapsulated class by making all the data members of the class private

- Java Bean class is the example of fully encapsulated class


1. Advantage

- You can make the class read-only or write-only

- It provides you the control over the data

2. Example


'Back-End > Java_1' 카테고리의 다른 글

[Java] Multithreading in java  (0) 2016.10.05
[Java] Call by value  (0) 2016.09.13
[Java] Package  (0) 2016.09.12
[Java] Interface  (0) 2016.09.12
[Java] Abstract class  (0) 2016.09.12
블로그 이미지

리딩리드

,