Get hired

Post a Job

Labels

Get Hired

Jobs from Indeed
Showing posts with label core java. Show all posts
Showing posts with label core java. Show all posts

Friday, June 1, 2018

Multithreading : Part 14 - Producer - Consumer Problem


Inter thread communication in Java Multithreading

Wednesday, May 9, 2018

Java Exception Handling | #5 | Custom exception class

Sometime we need our own custom exception class to work with. Here I have discussed about two different ways to create custom exception class.

Please do like, comment and share to rich to more needy people.

Wednesday, May 2, 2018

Multithreading : Part 13 - Synchronized block

How to use synchronized block, if the shared object is not pre-monitored, that is, if the designer of shared object has not monitored or synchronized it's method.

Sunday, March 25, 2018

Multithreading : Part 12 - Synchronization


A small java program to understand the need of synchronization.

Multithreading : Part 11 - Synchronization needed in real life



When there are many threads trying to access one shared resource, and are trying to fight over priorities, it isn’t good for your program. You might face inconsistency issues or unexpected thread interference.
To make sure a resource is being used by just one thread at a time, we make use of synchronization.
Just imagine this as a snack someone offers to you and your family when you visit their house. Each person in the room is a thread, and that delicious snack in the middle is a shared resource. Now wearing a mask of a good lad you are supposed to allow everyone to get a piece of it. That’s you and your siblings behaving in a synchronized way. That’s what synchronization in Java is about too.

Wednesday, March 14, 2018

How to create executable jar file

https://youtu.be/ex2TtJ_9aIk

Multithreading : Part 10 : create thread with Runnable

https://youtu.be/hEeb-NN0nb4

Multithreading : Part 9 : create thread

https://youtu.be/_FmskGFrEvg

Thread vs Runnable

Java lets you create thread in following two ways:-
By implementing the Runnable interface.
By extending the Thread
Let’s see how both the ways help in implementing Java thread.
Runnable Interface
The easiest way to create a thread is to create a class that implements the Runnable interface.
To implement Runnable interface, a class need only implement a single method called run( ), which is declared like this:
public void run( )
Inside run( ), we will define the code that constitutes the new thread.
Example:
public class MyClass implements Runnable {
public void run(){
System.out.println("MyClass is running");
}
}
To execute the run() method by a thread, pass an instance of MyClass to a Thread in its constructor as follows:
Thread t1 = new Thread(new MyClass ());
t1.start();
When the thread is started it will call the run() method of the MyClass instance instead of executing its own run() method. The above example would print out the text “MyClass is running“.
Extending Java Thread
The second way to create a thread is to create a new class that extends Thread, then override the run() method and then to create an instance of that class. The run() method is what is executed by the thread after you call start(). Here is an example of creating a Java Thread subclass:
public class MyClass extends Thread {
public void run(){
System.out.println("MyClass is running");
}
}
To create and start the above thread you can do like this:
MyClass t1 = new MyClass ();
t1.start();
When the run() method executes it will print out the text “MyClass is running“.