SlideShare a Scribd company logo
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 6
Mathematical foundations of Multithreaded programming
concepts in Java language
Manoj Kumar Srivastav
Indira Gandhi National Open University
St. Xavier’s College (Autonomous), Kolkata,
Pin Code-700016, India
Dr. Asoke Nath
Associate Professor, Department of Computer
Science, St. Xavier’s College (Autonomous),
Kolkata, Pin code-700016, India
Abstract-The mathematical description of object oriented language has already been developed by Srivastav et al. The
authors have already published papers where they have shown that it is possible to describe programming language
such as C, Java using simple mathematical sets and relations. The authors have established that it is possible to
describe object oriented language like Java and its various aspects such as object, class, inheritance using simple
mathematical models. In the present study the authors have proposed the mathematical modeling of Multi threaded
programming in java language. The authors have tried to explore the single threaded program and as well as multi
threaded program using simple mathematical modeling. The same idea may be applied to C# language also
Keyword---object oriented, modeling, multithreaded, java, C#
I. INTRODUCTION
The term ‘thread’ plays an important role in object oriented programming in Java. Actually a thread is ‘a single
sequential flow of control within a program.’ The concept of single thread is quite simple to understand and it becomes
somewhat complex when there are multithreads running simultaneously, each performing different tasks within a single
program. This can be enabled by multithreading where we can write program containing multiple path of execution,
running concurrently, within a single program .In other words we can say that “ a single program having multiple
threads , executing concurrently, can be termed as multithreaded program.”
Definition of Multithreading : Multithreading is a conceptual programming paradigm where a program (process) into
two or more subprogram (processes), which can be implemented at the same time in parallel. For example, one
subprogram can display animation on the screen while another may build the next animation to be displayed. This is
something similar to dividing tasks into subtasks and assigning them.
Main Thread
Main module method
start start start
switching switching
Thread CThread BThread A
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 7
It is important to remember that ‘thread running in parallel’ does not really mean that they actually run at the same time.
Since all the threads are running on a single processor, the flow of execution is shared between the threads.
Multithreading and memory space: Multithreading is a actually a form of multitasking. Multitasking can either be
process-based or thread-based. If we assume some programs as processes, the process-based multitasking is nothing but
execution of more than one program concurrently.
On the other hand, thread-based multitasking is executing a program having more than one thread, performing different
tasks simultaneously. Processes are heavyweight tasks, while threads are lightweight’s tasks. In process-based
multitasking, different processes are actually different programs, thus they share different address spaces. The context
switching of CPU from one process to another requires more overhead as different spaces are involved in the same. On
the contrary, the thread-based multitasking, different threads are part of the same program, thus they share the same
address space and context switching of CPU occurs within the program, i.e within the same address space.
Multitasking:
Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize the CPU.
Multitasking can be achieved by two ways:
(i)Process-based Multitasking(Multiprocessing)
(ii)Thread-based Multitasking(Multithreading)
(i)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,
updating lists etc.
(ii) Thread-based Multitasking (Multithreading):
Threads share the same address space.
Thread is lightweight.
Cost of communication between the thread is low.
Note:At least one process is required for each thread.
II. MATHEMATICAL DESCRIPTION OF MULTITHREADING
Mathematical Description of class and object: Object-Oriented programming language is based on the following
properties:
(i) Class and Object
(ii) Data Abstraction and Encapsulation
(iii) Inheritance
(iv) Polymorphism.
Class is a collection of objects of similar type.
Set: A set is well- defined collection of distinct objects of our perception or our thought ,to be conceived as a whole.
Set of sets: we have defined a set as a collection of its elements. If the elements be set themselves, then we have a family
of sets, or set of sets. For example, the collection of all subsets of a non-empty set S is a set of sets. This set is said to be
the power set of S and is denoted by P(S). Class may be defined as follows: -
In set theory and its application throughout mathematics, a class is collection of sets where each set has some common
property. The members of a class are countable.
So therefore, class={ sets : where all members have some common property}
The basic form of a class in object –oriented programming is
class classname
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 8
{ parameter declaration;
Method declaration;
}
Object: The members of a class are called an object. Since the members of a class is a set .Therefore it should possesses
some property. Objects are real world entity such as pen, chair, tables,etc.
Similar comparision between set theory and object oriented language :
Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. Any entity
that has state and behavior is known as an object. For example: chair, pen, table, etc. It can be physical and logical.
Collection of objects is called class. It is a logical entity. Any programming problem is analyzed in terms of objects and
the nature of communication between them. An object takes up space in the memory and has an associated address
like structure in C.
Thus, class is a set of object and object is a set having some common feature. We can write the class by the symbol ,
, ……etc and object by X,Y, Z……. etc.
MEMORY SPACE :An object is in Java is essentially a block of memory that contains space to store all instance
variables. i.e each object of a class contain an address in memory space. Memory space for an object={address of the
instance variables: variables are members of class}
Creating an object is also referred to as instantiating an object. Objects in Java are created using the new operator .The
new operator creates an object of the specified class and returns a reference to that object. Therefore the address of the
new object is changed.
Initial object has an address New object have new address
Therefore we define a mapping f:(X,τ)  (Y,σ) such that f(address of object)=address of new object[ Here X and Y are
object set and τ are set of sets with respect to object X and σ are set of sets with respect to object Y. Actually τ represents
classes for domain and σ represents class for range in the above function and f represents main function.
Mathematical Explanation of Multithreading:
A unique property of Java is its support for multithreading .That is, Java enables us to use multiple flows of control in
developing program. Each flow of control may be thought of as a separate tiny program (or module ) known as thread
that runs in parallel to others.
Let (X1,τ1
), (X2,τ2
), (X3,τ3
), …….. (Xn, τ n
) be representing the n-threads and may be running parallel and are
subprogram of main threads/program (X,τ). Let (Y,τ) be representing new threads(objects).
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 9
(X1,τ1
)
(X2,τ2
) (X, τ) (Y,τ)
(X3,τ3
)
( Xn, τ n)
Mathematically, the function can occurs as follows:
Let f1 : (X1,τ1) (X,τ),
f2 : (X2,τ2) (X,τ),
f3 : (X3,τ3) (X,τ),
………………………………….
fn : (Xn,τn) (X,τ), and finally, the function f :(X, τ) (Y ,τ) ,i.e the address of the thread (X1,τ1) , (X2,τ2),
(X3,τ3) ………………………… (Xn ,τn) mapping to the thread (X ,τ) and finally the address of the thread (X ,τ)
maps to new object/thread (Y,τ).Thus we can say that f(f i) : (X ,τ) (Y ,τ),
i.e . f (f i( (Address of domain))=address of range ,for i=1,2,3,………,n.
Example :Illustrate with an example on multithreading in Java.
Class A extends Thread
{
public void run()
{
for(int i=1; i<=5; i++)
{
System.out.println(“t From Thread A : = “ +i);
}
System.out.println(“ Exit from A”);
}
}
Class B extends Thread
{
public void run()
{
for(int i=1; i<=5; i++)
{
System.out.println(“t From Thread A : = “ +i);
}
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 10
System.out.println(“ Exit from A”);
}
}
Class C extends Thread
{
public void run()
{
for(int i=1; i<=5; i++)
{
System.out.println(“t From Thread A : = “ +i);
}
System.out.println(“ Exit from A”);
}
}
Class ThreadTest
{
public static void main(String args[])
{
new A().start();
new B().start();
new C().start();
}
}
Let us explain the example mathematically:
Class A extends thread i.e Taking
the address of class A
Class B extends thread i.e Taking
the address of class B
Class C extends thread i.e Taking
the address of class C
III MATHEMATICAL PROPERTIES OF THE MULTITHREADING
Properties(i):The space (X1,τ1) , (X2,τ2), (X3,τ3) ………………………… (Xn ,τn) are disconnected space.All the
threads are disconnected.
[ Definition of disconnected space.Then a subset E of X is said to be disconnected iff there exist two non-empty
separated set A and B such that E=A B.
Separated Set : :Let ( X, τ ) be a topological space. Two non empty subset A and B of X are said to be separated if and
only if A ∩ Bc
= and AC
∩ B= ]
Properties (ii) :Two sets are separated if and only if they are disjoint and neither of them contains limit point of the
other. Similarly all threads runs separately and output given by each threads does not depends on any threads.
Properties (iii) Subset of separated sets are separated. The thing can be illustrated by the following diagram for the
multithreading.
Class
threadTest.i.e
taking the
address of
thread Test
New object is
created.i.e
taking the
address of new
object.
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 11
Thread1 some parts of threads running
Thread 2 all parts of the thread running Main Thread New object /class/thread created
Thread 3 some parts of threads are in the rest mode
//:class anthread _2: Write a program in java to implement
//multithreaded program : Use yield(), sleep(), stop() method
import java.io.*;
class thread_A extends Thread
{
public void run()
{
int i,s,n;
try
{
System.out.println("nEntered in thread_A");
n=4;
s=0;
for(i=1;i<=n;i++)
{
s=s+i;
System.out.println("i="+i+" s="+s);
if(i==3)
{
System.out.println("nthread_A goes to sleep mode");
sleep(1000);
System.out.println("nOut of sleep mode in thread_A");
}
}
}
catch(Exception e){}
}
}
class thread_B extends Thread
{
public void run()
{
int j,p,m;
System.out.println("nEntered in thread_B");
m=4;
________
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 12
p=1;
for(j=1;j<=m;j++)
{
p=p*j;
System.out.println("j="+j+" p="+p);
if(j==3)
{
System.out.println("nthread_A goes to yield() mode");
yield();
System.out.println("nOut of yield() mode in thread_B");
}
}
}
}
class thread_C extends Thread
{
public void run()
{
int k,s1,d,k1;
System.out.println("nEntered in thread_C");
k=1234;
k1=k;
s1=0;
while(k1 != 0)
{
d=k1%10;
s1=s1+d;
System.out.println("k1="+k1+" d="+d);
if(k1<100)
{
System.out.println("nthread_C goes to stop() mode");
stop();
System.out.println("nOut of stop() mode in thread_C");
}
k1=k1/10;
}
}
}
class anthread_2
{
public static void main(String args[])throws IOException
{
thread_A A=new thread_A();
thread_B B=new thread_B();
thread_C C=new thread_C();
System.out.println("Calling thread_A");
A.start();
System.out.println("Calling thread_B");
B.start();
System.out.println("Calling thread_C");
C.start();
System.out.println("nEnd of main thread");
}
}
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 13
Remarks : There may be the situation in which some threads are running and some are in the stop mode or some
parts of a thread are working..But in all the situation each threads are separated.
class thread_A extends Thread sleep() mode may be working in some parts here.
class thread_B extends Thread yield() mode may be working on the some stage of
thread
class thread_C extends Thread stop() mode is working on the some stage of thread
Thread Priority : In Java, each thread is assigned a priority, which affects the order in which it is scheduled for
running. Mathematically, thread priority are the set which assigned with some indexed number and having some fixed
probability value in all the situation.
//anthread_3.java: Write a program in java to implement
//multithreaded program: Use setPriority(), sleep(), stop()
//method
import java.io.*;
class thread_A extends Thread
{
public void run()
{
int i,s,n;
try
{
System.out.println("nEntered in thread_A");
n=4;
s=0;
for(i=1;i<=n;i++)
{
s=s+i;
System.out.println("i="+i+" s="+s);
if(i==3)
{
System.out.println("nthread_A goes to sleep mode");
sleep(1000);
System.out.println("nOut of sleep mode in thread_A");
}
}
}
catch(Exception e){}
}
}
class thread_B extends Thread
{
public void run()
{
int j,p,m;
System.out.println("nEntered in thread_B");
m=4;
p=1;
for(j=1;j<=m;j++)
{
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 14
p=p*j;
System.out.println("j="+j+" p="+p);
if(j==3)
{
System.out.println("nthread_A goes to yield() mode");
yield();
System.out.println("nOut of yield() mode in thread_B");
}
}
}
}
class thread_C extends Thread
{
public void run()
{
int k,s1,d,k1;
System.out.println("nEntered in thread_C");
k=1234;
k1=k;
s1=0;
while(k1 != 0)
{
d=k1%10;
s1=s1+d;
System.out.println("k1="+k1+" d="+d);
if(k1<100)
{
System.out.println("nthread_C goes to stop() mode");
stop();
System.out.println("nOut of stop() mode in thread_C");
}
k1=k1/10;
}
}
}
}
}
class anthread_3
{
public static void main(String args[])throws IOException
{
thread_A A=new thread_A();
thread_B B=new thread_B();
thread_C C=new thread_C();
System.out.println("Calling thread_A");
A.setPriority(Thread.MAX_PRIORITY);
B.setPriority(Thread.MIN_PRIORITY);
C.setPriority(Thread.NORM_PRIORITY);
System.out.println("Calling thread_C");
C.start();
System.out.println("Calling thread_B");
B.start();
System.out.println("Calling thread_A");
A.start();
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 15
System.out.println("nEnd of main thread");
}
}
Remarks :
Threads Probability
A.setPriority(Thread.
MAX_PRIORITY);
Thread has highest value of probability of running
B.setPriority(Thread.MI
N_PRIORITY);
Thread has lowest value of probability of running
C.setPriority(Thread.N
ORM_PRIORITY);
Thread has the value of probability that lies between highest value and lowest
value of probability of running of threads.
Definition of Probability of an Event: If there are n elementary events associated with a random experiment and m of
them are favourable to an event A, then the probability of happening or occurrence of A is denoted by P(A) and is
defined in the ratio m/n. Thus,P(A)=m/n, clearly, 0≤m≤n.
Therefore , 0≤m/n≤1
0≤P(A)≤ 1. If P(A)=1, then A is called certain events and A is called impossible events.
The value of thread priority lies between 1-10,The Min_Priority,Norm _Priority and Max_Priority have distinct value
and it are respectively 1,5 and 10 .
IV .LIFE CYCLE OF A THREAD (THREAD STATES)
A thread can be in one of the five states in the thread. According to sun, there is only 4 states new, runnable, non-
runnable and terminated. There is no running state. But for better understanding the threads, we are explaining it in the 5
states. The life cycle of the thread is controlled by JVM. The thread states are as follows:
1. New
2. Runnable
3. Running
4. Non-Runnable (Blocked)
5. Terminated
1)New :
The thread is in new state if you create an instance of Thread class but before the invocation of start() method.
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 16
2)Runnable
The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the
running thread.
3)Running
The thread is in running state if the thread scheduler has selected it.
4)Non-Runnable (Blocked)
This is the state when the thread is still alive, but is currently not eligible to run.
5)Terminated
A thread is in terminated or dead state when its run() method exits.
Mathematical Description Of State Transition diagram of a thread :
Let (X,τ1) denotes the newborn thread where X is object and τ1 denotes the class (or thread) with respect to
object X.
Let (Y,τ2) denotes the runnable/running thread where Y is object and τ2 denotes the class (or thread) with
respect to object Y
Let (Z,τ3) denotes the Blocked thread where Z is object and τ3denotes the class (or thread) with respect to
object Z
Let (D,τ4) denotes the dead/ killed thread where D is object and τ4denotes the class (or thread) with respect to
object D
f1 f
g
f2 f3 h
Note : Let us assume the following mapping occurs in the different memory spaces.
Here f1 :(X,τ1) (Y,τ2)
f2 :(Y,τ2) (Z,τ3)
f3 :(Z,τ3) (Y,τ2)
f :(X,τ1) (D,τ4)
g : (Y,τ2) ( D,τ4)
h :(Z,τ3) (D,τ4)
Case 1:Newborn state to Dead state: Here ,we can define the function f :(X,τ1) (D,τ4)
Such that f(address value of newborn thread)=address value of killed thread. Actually ,we may use stop() as a function in
the stage.
Case 2:Newborn state to Dead state via running and runnable state: Here we can define the function f1
:(X,τ1) (Y,τ2) and g: (Y,τ2) (D,τ4) such that g(f) : :(X,τ1) (D,τ4)
i.e. g(f(address value of new born state))= address value of dead state.
Case 3: Newborn state to Dead state via running , runnable state and Blocked state::In this stage, we can
define the composite function as follows :
h(f2(f1)) :(X,τ1) ( D,τ4)
h(f2(f1 (address value of new born state)))= address value of dead state
or
g(f3(f2(f1))) : (X,τ1) ( D,τ4)
g(f3(f2(f1 (address value of new born state))))= address value of dead state.
(X,τ1 )
(Y,τ2)
(Z,τ3)
(D,τ4)
International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O)
Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P)
www.ijiris.com
_________________________________________________________________________________________________
© 2014, IJIRIS- All Rights Reserved Page - 17
V. CONCLUSION
Multithreading is a process where we can make the correlation between the multithreading and disconnected space of a
Topological scope. The embedding of the thread in to the main threads will be helpful to justify the memory space of
different threads. Life Cycle of a thread can also be described mathematically and it also obeys the properties of
disconnected space.
REFERENCES
[1] Manoj Kumar Srivastav , Asoke Nath Mathematical modeling of various statements of C-type Language, ,
International Journal of Advanced Computer Research(IJACR), Vol-3,Number-1, Issue-13, Page:79-87 Dec(2013).
[2] Manoj Kumar Srivastava, Asoke Nath Mathematical Description of variables, pointers, structures, Unions used in C-
type language, , Joiurnal of Global Research Computer Science, Vol-5, No-2, Page:24-29, Feb(2014)
[3] Manoj Kumar Srivastav, Asoke Nath, A Mathematical Modeling of Object Oriented Programming Language : a case
study on Java programming language, Current Trends in Technology and Science(CTTS) Vol-3, Issue-3, Page 134-
141,(2014).
[4] Manoj Kumar Srivastav, Asoke Nath, Analysis of Compilation Errors, Runtime Errors, Reliability and Validity of a
Program: A Case Study on C-language : IJISET - International Journal of Innovative Science, Engineering &
Technology, Vol. 1 Issue 3, May 2014. Page-281-288.
[5] E Balaguruswamy- Programming with Java-TataMcGrawHill EductionP rivate Limited.,2011
[6] Sachin Malhotra, Sourabh Choudhary- Programming in Java- OXFORD University Press,2012
[7] Herbert Schildt, Java TM 2: The Complete Reference, TataMcGraw-Hill Publishing Company Limited,2001
[8] Satish Jain,Vineeta Pillai,Kratika, Introduction to Object Oriented Programming through Java,BPB Publications,2011
[9] S.K.Mapa, Real Analysis , Asoke Prakasan 1998
[10] S.K.Mapa Higher Algebra, -Sarat Book Distribution,2000
[11] K.D.Joshi-Topology.New Age International Publiocation.
[12] J.N Sharma, "Topology", Krishna Prakashan Media(p)Ltd., Meerut, (2000)
[13]R.S.aggarwal-Topology-S.chand publication.
[14]James R Munkers-Topology- Pearson Education Asia, 2001
[15] www.javatpoint.com
[16] R.D.Sharma. Mathematics class xi-. Danapat Rai Publications(P) LTD.
Ad

Recommended

Deep Learning for Search
Deep Learning for Search
Bhaskar Mitra
 
Object oriented programming concept
Object oriented programming concept
Pina Parmar
 
Presentation on Text Classification
Presentation on Text Classification
Sai Srinivas Kotni
 
Data Structures 2004
Data Structures 2004
Sanjay Goel
 
Object oriented programming concepts
Object oriented programming concepts
rahuld115
 
Object database standards, languages and design
Object database standards, languages and design
Dabbal Singh Mahara
 
Oops
Oops
Maheswarikrishnasamy
 
Learning scientific scholar representations using a combination of collaborat...
Learning scientific scholar representations using a combination of collaborat...
Ankush Khandelwal
 
Deep Learning for Search
Deep Learning for Search
Bhaskar Mitra
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6
RhettB
 
Tdm probabilistic models (part 2)
Tdm probabilistic models (part 2)
KU Leuven
 
Text categorization
Text categorization
KU Leuven
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
Prem Lamsal
 
Characteristics of oop
Characteristics of oop
Rasim Izhar Ali
 
W3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed Arrays
Changhwan Yi
 
Mapping Subsets of Scholarly Information
Mapping Subsets of Scholarly Information
Paul Houle
 
[ppt]
[ppt]
butest
 
Text classification-php-v4
Text classification-php-v4
Glenn De Backer
 
Text classification using Text kernels
Text classification using Text kernels
Dev Nath
 
Boolean,vector space retrieval Models
Boolean,vector space retrieval Models
Primya Tamil
 
Farthest Neighbor Approach for Finding Initial Centroids in K- Means
Farthest Neighbor Approach for Finding Initial Centroids in K- Means
Waqas Tariq
 
Term weighting
Term weighting
Primya Tamil
 
Data mining classifiers.
Data mining classifiers.
ShwetaPatil174
 
Oops slide
Oops slide
Ashok Sharma
 
20070702 Text Categorization
20070702 Text Categorization
midi
 
Text Classification, Sentiment Analysis, and Opinion Mining
Text Classification, Sentiment Analysis, and Opinion Mining
Fabrizio Sebastiani
 
Fuzzy Clustering(C-means, K-means)
Fuzzy Clustering(C-means, K-means)
UMBC
 
Object Oriented Programming
Object Oriented Programming
AyushiDubey19
 
WooCommerce Development Company Dallas
WooCommerce Development Company Dallas
Thrive Internet Marketing TX
 
Socialmediacourse 1
Socialmediacourse 1
Andy Pemberton
 

More Related Content

What's hot (20)

Deep Learning for Search
Deep Learning for Search
Bhaskar Mitra
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6
RhettB
 
Tdm probabilistic models (part 2)
Tdm probabilistic models (part 2)
KU Leuven
 
Text categorization
Text categorization
KU Leuven
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
Prem Lamsal
 
Characteristics of oop
Characteristics of oop
Rasim Izhar Ali
 
W3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed Arrays
Changhwan Yi
 
Mapping Subsets of Scholarly Information
Mapping Subsets of Scholarly Information
Paul Houle
 
[ppt]
[ppt]
butest
 
Text classification-php-v4
Text classification-php-v4
Glenn De Backer
 
Text classification using Text kernels
Text classification using Text kernels
Dev Nath
 
Boolean,vector space retrieval Models
Boolean,vector space retrieval Models
Primya Tamil
 
Farthest Neighbor Approach for Finding Initial Centroids in K- Means
Farthest Neighbor Approach for Finding Initial Centroids in K- Means
Waqas Tariq
 
Term weighting
Term weighting
Primya Tamil
 
Data mining classifiers.
Data mining classifiers.
ShwetaPatil174
 
Oops slide
Oops slide
Ashok Sharma
 
20070702 Text Categorization
20070702 Text Categorization
midi
 
Text Classification, Sentiment Analysis, and Opinion Mining
Text Classification, Sentiment Analysis, and Opinion Mining
Fabrizio Sebastiani
 
Fuzzy Clustering(C-means, K-means)
Fuzzy Clustering(C-means, K-means)
UMBC
 
Object Oriented Programming
Object Oriented Programming
AyushiDubey19
 
Deep Learning for Search
Deep Learning for Search
Bhaskar Mitra
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6
RhettB
 
Tdm probabilistic models (part 2)
Tdm probabilistic models (part 2)
KU Leuven
 
Text categorization
Text categorization
KU Leuven
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
Prem Lamsal
 
W3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed Arrays
Changhwan Yi
 
Mapping Subsets of Scholarly Information
Mapping Subsets of Scholarly Information
Paul Houle
 
Text classification-php-v4
Text classification-php-v4
Glenn De Backer
 
Text classification using Text kernels
Text classification using Text kernels
Dev Nath
 
Boolean,vector space retrieval Models
Boolean,vector space retrieval Models
Primya Tamil
 
Farthest Neighbor Approach for Finding Initial Centroids in K- Means
Farthest Neighbor Approach for Finding Initial Centroids in K- Means
Waqas Tariq
 
Data mining classifiers.
Data mining classifiers.
ShwetaPatil174
 
20070702 Text Categorization
20070702 Text Categorization
midi
 
Text Classification, Sentiment Analysis, and Opinion Mining
Text Classification, Sentiment Analysis, and Opinion Mining
Fabrizio Sebastiani
 
Fuzzy Clustering(C-means, K-means)
Fuzzy Clustering(C-means, K-means)
UMBC
 
Object Oriented Programming
Object Oriented Programming
AyushiDubey19
 

Viewers also liked (15)

WooCommerce Development Company Dallas
WooCommerce Development Company Dallas
Thrive Internet Marketing TX
 
Socialmediacourse 1
Socialmediacourse 1
Andy Pemberton
 
куаныш аманжолов+шиномонтажка+идея
куаныш аманжолов+шиномонтажка+идея
Куаныш аманжолов
 
Artilharia copas regionais
Artilharia copas regionais
Rafael Passos
 
VANCL logistics operations mode selection analysis
VANCL logistics operations mode selection analysis
AM Publications,India
 
Artilharia brasileirão
Artilharia brasileirão
Rafael Passos
 
Artilharia copas regionais
Artilharia copas regionais
Rafael Passos
 
Life Cycle Cost Analysis
Life Cycle Cost Analysis
imagstech
 
mohamed gamal elseidy cv
mohamed gamal elseidy cv
mohamed elseidy
 
Lol
Lol
Berlinda27
 
New Logo Launch
New Logo Launch
cpack
 
Brief Introduction
Brief Introduction
ceilabb10
 
What next for Facebook
What next for Facebook
Andy Pemberton
 
Episode 55 : Conceptual Process Synthesis-Design
Episode 55 : Conceptual Process Synthesis-Design
SAJJAD KHUDHUR ABBAS
 
Soft computing (ANN and Fuzzy Logic) : Dr. Purnima Pandit
Soft computing (ANN and Fuzzy Logic) : Dr. Purnima Pandit
Purnima Pandit
 
куаныш аманжолов+шиномонтажка+идея
куаныш аманжолов+шиномонтажка+идея
Куаныш аманжолов
 
Artilharia copas regionais
Artilharia copas regionais
Rafael Passos
 
VANCL logistics operations mode selection analysis
VANCL logistics operations mode selection analysis
AM Publications,India
 
Artilharia brasileirão
Artilharia brasileirão
Rafael Passos
 
Artilharia copas regionais
Artilharia copas regionais
Rafael Passos
 
Life Cycle Cost Analysis
Life Cycle Cost Analysis
imagstech
 
mohamed gamal elseidy cv
mohamed gamal elseidy cv
mohamed elseidy
 
New Logo Launch
New Logo Launch
cpack
 
Brief Introduction
Brief Introduction
ceilabb10
 
What next for Facebook
What next for Facebook
Andy Pemberton
 
Episode 55 : Conceptual Process Synthesis-Design
Episode 55 : Conceptual Process Synthesis-Design
SAJJAD KHUDHUR ABBAS
 
Soft computing (ANN and Fuzzy Logic) : Dr. Purnima Pandit
Soft computing (ANN and Fuzzy Logic) : Dr. Purnima Pandit
Purnima Pandit
 
Ad

Similar to Mathematical foundations of Multithreaded programming concepts in Java language (20)

Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Sachintha Gunasena
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
BalamuruganV28
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Object-Oriented-Prog_MultiThreading.pptx
Object-Oriented-Prog_MultiThreading.pptx
NasreenTaj20
 
advanced java programming paradigms presentation
advanced java programming paradigms presentation
PriyadharshiniG41
 
3. jvm
3. jvm
Indu Sharma Bhardwaj
 
Unit 5 - Java Multihhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaathreading.pdf
Unit 5 - Java Multihhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaathreading.pdf
kassyemariyam21
 
Javascript
Javascript
Sheldon Abraham
 
java programming concept multithreading multitasking.pdf
java programming concept multithreading multitasking.pdf
doraeshin04
 
Multithreading.pptx
Multithreading.pptx
ssuserfcae42
 
multithreading.pptx
multithreading.pptx
Sravanibitragunta
 
PACKAGES, MULTITHREADED PROGRAMMING & MANAGING ERRORS AND EXCEPTIONS in java
PACKAGES, MULTITHREADED PROGRAMMING & MANAGING ERRORS AND EXCEPTIONS in java
JayanthiM19
 
Java_Interview Qns
Java_Interview Qns
ManikandanRamanujam
 
web programming-Multithreading concept in Java.ppt
web programming-Multithreading concept in Java.ppt
mcjaya2024
 
Java Multithreading
Java Multithreading
Ganesh Samarthyam
 
C++0x
C++0x
Vaibhav Bajaj
 
Semantics
Semantics
Dr. Cupid Lucid
 
Semantics
Semantics
Jahanzeb Jahan
 
Java Threads: Lightweight Processes
Java Threads: Lightweight Processes
Isuru Perera
 
Multithreading in java
Multithreading in java
Raghu nath
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Sachintha Gunasena
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
BalamuruganV28
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Object-Oriented-Prog_MultiThreading.pptx
Object-Oriented-Prog_MultiThreading.pptx
NasreenTaj20
 
advanced java programming paradigms presentation
advanced java programming paradigms presentation
PriyadharshiniG41
 
Unit 5 - Java Multihhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaathreading.pdf
Unit 5 - Java Multihhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaathreading.pdf
kassyemariyam21
 
java programming concept multithreading multitasking.pdf
java programming concept multithreading multitasking.pdf
doraeshin04
 
Multithreading.pptx
Multithreading.pptx
ssuserfcae42
 
PACKAGES, MULTITHREADED PROGRAMMING & MANAGING ERRORS AND EXCEPTIONS in java
PACKAGES, MULTITHREADED PROGRAMMING & MANAGING ERRORS AND EXCEPTIONS in java
JayanthiM19
 
web programming-Multithreading concept in Java.ppt
web programming-Multithreading concept in Java.ppt
mcjaya2024
 
Java Threads: Lightweight Processes
Java Threads: Lightweight Processes
Isuru Perera
 
Multithreading in java
Multithreading in java
Raghu nath
 
Ad

Recently uploaded (20)

Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Which Hiring Management Tools Offer the Best ROI?
Which Hiring Management Tools Offer the Best ROI?
HireME
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
Microsoft-365-Administrator-s-Guide1.pdf
Microsoft-365-Administrator-s-Guide1.pdf
mazharatknl
 
ElectraSuite_Prsentation(online voting system).pptx
ElectraSuite_Prsentation(online voting system).pptx
mrsinankhan01
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
The Anti-Masterclass Live - Peak of Data & AI 2025
The Anti-Masterclass Live - Peak of Data & AI 2025
Safe Software
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Which Hiring Management Tools Offer the Best ROI?
Which Hiring Management Tools Offer the Best ROI?
HireME
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
Microsoft-365-Administrator-s-Guide1.pdf
Microsoft-365-Administrator-s-Guide1.pdf
mazharatknl
 
ElectraSuite_Prsentation(online voting system).pptx
ElectraSuite_Prsentation(online voting system).pptx
mrsinankhan01
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
The Anti-Masterclass Live - Peak of Data & AI 2025
The Anti-Masterclass Live - Peak of Data & AI 2025
Safe Software
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 

Mathematical foundations of Multithreaded programming concepts in Java language

  • 1. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 6 Mathematical foundations of Multithreaded programming concepts in Java language Manoj Kumar Srivastav Indira Gandhi National Open University St. Xavier’s College (Autonomous), Kolkata, Pin Code-700016, India Dr. Asoke Nath Associate Professor, Department of Computer Science, St. Xavier’s College (Autonomous), Kolkata, Pin code-700016, India Abstract-The mathematical description of object oriented language has already been developed by Srivastav et al. The authors have already published papers where they have shown that it is possible to describe programming language such as C, Java using simple mathematical sets and relations. The authors have established that it is possible to describe object oriented language like Java and its various aspects such as object, class, inheritance using simple mathematical models. In the present study the authors have proposed the mathematical modeling of Multi threaded programming in java language. The authors have tried to explore the single threaded program and as well as multi threaded program using simple mathematical modeling. The same idea may be applied to C# language also Keyword---object oriented, modeling, multithreaded, java, C# I. INTRODUCTION The term ‘thread’ plays an important role in object oriented programming in Java. Actually a thread is ‘a single sequential flow of control within a program.’ The concept of single thread is quite simple to understand and it becomes somewhat complex when there are multithreads running simultaneously, each performing different tasks within a single program. This can be enabled by multithreading where we can write program containing multiple path of execution, running concurrently, within a single program .In other words we can say that “ a single program having multiple threads , executing concurrently, can be termed as multithreaded program.” Definition of Multithreading : Multithreading is a conceptual programming paradigm where a program (process) into two or more subprogram (processes), which can be implemented at the same time in parallel. For example, one subprogram can display animation on the screen while another may build the next animation to be displayed. This is something similar to dividing tasks into subtasks and assigning them. Main Thread Main module method start start start switching switching Thread CThread BThread A
  • 2. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 7 It is important to remember that ‘thread running in parallel’ does not really mean that they actually run at the same time. Since all the threads are running on a single processor, the flow of execution is shared between the threads. Multithreading and memory space: Multithreading is a actually a form of multitasking. Multitasking can either be process-based or thread-based. If we assume some programs as processes, the process-based multitasking is nothing but execution of more than one program concurrently. On the other hand, thread-based multitasking is executing a program having more than one thread, performing different tasks simultaneously. Processes are heavyweight tasks, while threads are lightweight’s tasks. In process-based multitasking, different processes are actually different programs, thus they share different address spaces. The context switching of CPU from one process to another requires more overhead as different spaces are involved in the same. On the contrary, the thread-based multitasking, different threads are part of the same program, thus they share the same address space and context switching of CPU occurs within the program, i.e within the same address space. Multitasking: Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize the CPU. Multitasking can be achieved by two ways: (i)Process-based Multitasking(Multiprocessing) (ii)Thread-based Multitasking(Multithreading) (i)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, updating lists etc. (ii) Thread-based Multitasking (Multithreading): Threads share the same address space. Thread is lightweight. Cost of communication between the thread is low. Note:At least one process is required for each thread. II. MATHEMATICAL DESCRIPTION OF MULTITHREADING Mathematical Description of class and object: Object-Oriented programming language is based on the following properties: (i) Class and Object (ii) Data Abstraction and Encapsulation (iii) Inheritance (iv) Polymorphism. Class is a collection of objects of similar type. Set: A set is well- defined collection of distinct objects of our perception or our thought ,to be conceived as a whole. Set of sets: we have defined a set as a collection of its elements. If the elements be set themselves, then we have a family of sets, or set of sets. For example, the collection of all subsets of a non-empty set S is a set of sets. This set is said to be the power set of S and is denoted by P(S). Class may be defined as follows: - In set theory and its application throughout mathematics, a class is collection of sets where each set has some common property. The members of a class are countable. So therefore, class={ sets : where all members have some common property} The basic form of a class in object –oriented programming is class classname
  • 3. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 8 { parameter declaration; Method declaration; } Object: The members of a class are called an object. Since the members of a class is a set .Therefore it should possesses some property. Objects are real world entity such as pen, chair, tables,etc. Similar comparision between set theory and object oriented language : Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. Any entity that has state and behavior is known as an object. For example: chair, pen, table, etc. It can be physical and logical. Collection of objects is called class. It is a logical entity. Any programming problem is analyzed in terms of objects and the nature of communication between them. An object takes up space in the memory and has an associated address like structure in C. Thus, class is a set of object and object is a set having some common feature. We can write the class by the symbol , , ……etc and object by X,Y, Z……. etc. MEMORY SPACE :An object is in Java is essentially a block of memory that contains space to store all instance variables. i.e each object of a class contain an address in memory space. Memory space for an object={address of the instance variables: variables are members of class} Creating an object is also referred to as instantiating an object. Objects in Java are created using the new operator .The new operator creates an object of the specified class and returns a reference to that object. Therefore the address of the new object is changed. Initial object has an address New object have new address Therefore we define a mapping f:(X,τ)  (Y,σ) such that f(address of object)=address of new object[ Here X and Y are object set and τ are set of sets with respect to object X and σ are set of sets with respect to object Y. Actually τ represents classes for domain and σ represents class for range in the above function and f represents main function. Mathematical Explanation of Multithreading: A unique property of Java is its support for multithreading .That is, Java enables us to use multiple flows of control in developing program. Each flow of control may be thought of as a separate tiny program (or module ) known as thread that runs in parallel to others. Let (X1,τ1 ), (X2,τ2 ), (X3,τ3 ), …….. (Xn, τ n ) be representing the n-threads and may be running parallel and are subprogram of main threads/program (X,τ). Let (Y,τ) be representing new threads(objects).
  • 4. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 9 (X1,τ1 ) (X2,τ2 ) (X, τ) (Y,τ) (X3,τ3 ) ( Xn, τ n) Mathematically, the function can occurs as follows: Let f1 : (X1,τ1) (X,τ), f2 : (X2,τ2) (X,τ), f3 : (X3,τ3) (X,τ), …………………………………. fn : (Xn,τn) (X,τ), and finally, the function f :(X, τ) (Y ,τ) ,i.e the address of the thread (X1,τ1) , (X2,τ2), (X3,τ3) ………………………… (Xn ,τn) mapping to the thread (X ,τ) and finally the address of the thread (X ,τ) maps to new object/thread (Y,τ).Thus we can say that f(f i) : (X ,τ) (Y ,τ), i.e . f (f i( (Address of domain))=address of range ,for i=1,2,3,………,n. Example :Illustrate with an example on multithreading in Java. Class A extends Thread { public void run() { for(int i=1; i<=5; i++) { System.out.println(“t From Thread A : = “ +i); } System.out.println(“ Exit from A”); } } Class B extends Thread { public void run() { for(int i=1; i<=5; i++) { System.out.println(“t From Thread A : = “ +i); }
  • 5. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 10 System.out.println(“ Exit from A”); } } Class C extends Thread { public void run() { for(int i=1; i<=5; i++) { System.out.println(“t From Thread A : = “ +i); } System.out.println(“ Exit from A”); } } Class ThreadTest { public static void main(String args[]) { new A().start(); new B().start(); new C().start(); } } Let us explain the example mathematically: Class A extends thread i.e Taking the address of class A Class B extends thread i.e Taking the address of class B Class C extends thread i.e Taking the address of class C III MATHEMATICAL PROPERTIES OF THE MULTITHREADING Properties(i):The space (X1,τ1) , (X2,τ2), (X3,τ3) ………………………… (Xn ,τn) are disconnected space.All the threads are disconnected. [ Definition of disconnected space.Then a subset E of X is said to be disconnected iff there exist two non-empty separated set A and B such that E=A B. Separated Set : :Let ( X, τ ) be a topological space. Two non empty subset A and B of X are said to be separated if and only if A ∩ Bc = and AC ∩ B= ] Properties (ii) :Two sets are separated if and only if they are disjoint and neither of them contains limit point of the other. Similarly all threads runs separately and output given by each threads does not depends on any threads. Properties (iii) Subset of separated sets are separated. The thing can be illustrated by the following diagram for the multithreading. Class threadTest.i.e taking the address of thread Test New object is created.i.e taking the address of new object.
  • 6. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 11 Thread1 some parts of threads running Thread 2 all parts of the thread running Main Thread New object /class/thread created Thread 3 some parts of threads are in the rest mode //:class anthread _2: Write a program in java to implement //multithreaded program : Use yield(), sleep(), stop() method import java.io.*; class thread_A extends Thread { public void run() { int i,s,n; try { System.out.println("nEntered in thread_A"); n=4; s=0; for(i=1;i<=n;i++) { s=s+i; System.out.println("i="+i+" s="+s); if(i==3) { System.out.println("nthread_A goes to sleep mode"); sleep(1000); System.out.println("nOut of sleep mode in thread_A"); } } } catch(Exception e){} } } class thread_B extends Thread { public void run() { int j,p,m; System.out.println("nEntered in thread_B"); m=4; ________
  • 7. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 12 p=1; for(j=1;j<=m;j++) { p=p*j; System.out.println("j="+j+" p="+p); if(j==3) { System.out.println("nthread_A goes to yield() mode"); yield(); System.out.println("nOut of yield() mode in thread_B"); } } } } class thread_C extends Thread { public void run() { int k,s1,d,k1; System.out.println("nEntered in thread_C"); k=1234; k1=k; s1=0; while(k1 != 0) { d=k1%10; s1=s1+d; System.out.println("k1="+k1+" d="+d); if(k1<100) { System.out.println("nthread_C goes to stop() mode"); stop(); System.out.println("nOut of stop() mode in thread_C"); } k1=k1/10; } } } class anthread_2 { public static void main(String args[])throws IOException { thread_A A=new thread_A(); thread_B B=new thread_B(); thread_C C=new thread_C(); System.out.println("Calling thread_A"); A.start(); System.out.println("Calling thread_B"); B.start(); System.out.println("Calling thread_C"); C.start(); System.out.println("nEnd of main thread"); } }
  • 8. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 13 Remarks : There may be the situation in which some threads are running and some are in the stop mode or some parts of a thread are working..But in all the situation each threads are separated. class thread_A extends Thread sleep() mode may be working in some parts here. class thread_B extends Thread yield() mode may be working on the some stage of thread class thread_C extends Thread stop() mode is working on the some stage of thread Thread Priority : In Java, each thread is assigned a priority, which affects the order in which it is scheduled for running. Mathematically, thread priority are the set which assigned with some indexed number and having some fixed probability value in all the situation. //anthread_3.java: Write a program in java to implement //multithreaded program: Use setPriority(), sleep(), stop() //method import java.io.*; class thread_A extends Thread { public void run() { int i,s,n; try { System.out.println("nEntered in thread_A"); n=4; s=0; for(i=1;i<=n;i++) { s=s+i; System.out.println("i="+i+" s="+s); if(i==3) { System.out.println("nthread_A goes to sleep mode"); sleep(1000); System.out.println("nOut of sleep mode in thread_A"); } } } catch(Exception e){} } } class thread_B extends Thread { public void run() { int j,p,m; System.out.println("nEntered in thread_B"); m=4; p=1; for(j=1;j<=m;j++) {
  • 9. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 14 p=p*j; System.out.println("j="+j+" p="+p); if(j==3) { System.out.println("nthread_A goes to yield() mode"); yield(); System.out.println("nOut of yield() mode in thread_B"); } } } } class thread_C extends Thread { public void run() { int k,s1,d,k1; System.out.println("nEntered in thread_C"); k=1234; k1=k; s1=0; while(k1 != 0) { d=k1%10; s1=s1+d; System.out.println("k1="+k1+" d="+d); if(k1<100) { System.out.println("nthread_C goes to stop() mode"); stop(); System.out.println("nOut of stop() mode in thread_C"); } k1=k1/10; } } } } } class anthread_3 { public static void main(String args[])throws IOException { thread_A A=new thread_A(); thread_B B=new thread_B(); thread_C C=new thread_C(); System.out.println("Calling thread_A"); A.setPriority(Thread.MAX_PRIORITY); B.setPriority(Thread.MIN_PRIORITY); C.setPriority(Thread.NORM_PRIORITY); System.out.println("Calling thread_C"); C.start(); System.out.println("Calling thread_B"); B.start(); System.out.println("Calling thread_A"); A.start();
  • 10. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 15 System.out.println("nEnd of main thread"); } } Remarks : Threads Probability A.setPriority(Thread. MAX_PRIORITY); Thread has highest value of probability of running B.setPriority(Thread.MI N_PRIORITY); Thread has lowest value of probability of running C.setPriority(Thread.N ORM_PRIORITY); Thread has the value of probability that lies between highest value and lowest value of probability of running of threads. Definition of Probability of an Event: If there are n elementary events associated with a random experiment and m of them are favourable to an event A, then the probability of happening or occurrence of A is denoted by P(A) and is defined in the ratio m/n. Thus,P(A)=m/n, clearly, 0≤m≤n. Therefore , 0≤m/n≤1 0≤P(A)≤ 1. If P(A)=1, then A is called certain events and A is called impossible events. The value of thread priority lies between 1-10,The Min_Priority,Norm _Priority and Max_Priority have distinct value and it are respectively 1,5 and 10 . IV .LIFE CYCLE OF A THREAD (THREAD STATES) A thread can be in one of the five states in the thread. According to sun, there is only 4 states new, runnable, non- runnable and terminated. There is no running state. But for better understanding the threads, we are explaining it in the 5 states. The life cycle of the thread is controlled by JVM. The thread states are as follows: 1. New 2. Runnable 3. Running 4. Non-Runnable (Blocked) 5. Terminated 1)New : The thread is in new state if you create an instance of Thread class but before the invocation of start() method.
  • 11. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 16 2)Runnable The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the running thread. 3)Running The thread is in running state if the thread scheduler has selected it. 4)Non-Runnable (Blocked) This is the state when the thread is still alive, but is currently not eligible to run. 5)Terminated A thread is in terminated or dead state when its run() method exits. Mathematical Description Of State Transition diagram of a thread : Let (X,τ1) denotes the newborn thread where X is object and τ1 denotes the class (or thread) with respect to object X. Let (Y,τ2) denotes the runnable/running thread where Y is object and τ2 denotes the class (or thread) with respect to object Y Let (Z,τ3) denotes the Blocked thread where Z is object and τ3denotes the class (or thread) with respect to object Z Let (D,τ4) denotes the dead/ killed thread where D is object and τ4denotes the class (or thread) with respect to object D f1 f g f2 f3 h Note : Let us assume the following mapping occurs in the different memory spaces. Here f1 :(X,τ1) (Y,τ2) f2 :(Y,τ2) (Z,τ3) f3 :(Z,τ3) (Y,τ2) f :(X,τ1) (D,τ4) g : (Y,τ2) ( D,τ4) h :(Z,τ3) (D,τ4) Case 1:Newborn state to Dead state: Here ,we can define the function f :(X,τ1) (D,τ4) Such that f(address value of newborn thread)=address value of killed thread. Actually ,we may use stop() as a function in the stage. Case 2:Newborn state to Dead state via running and runnable state: Here we can define the function f1 :(X,τ1) (Y,τ2) and g: (Y,τ2) (D,τ4) such that g(f) : :(X,τ1) (D,τ4) i.e. g(f(address value of new born state))= address value of dead state. Case 3: Newborn state to Dead state via running , runnable state and Blocked state::In this stage, we can define the composite function as follows : h(f2(f1)) :(X,τ1) ( D,τ4) h(f2(f1 (address value of new born state)))= address value of dead state or g(f3(f2(f1))) : (X,τ1) ( D,τ4) g(f3(f2(f1 (address value of new born state))))= address value of dead state. (X,τ1 ) (Y,τ2) (Z,τ3) (D,τ4)
  • 12. International Journal of Innovative Research in Information Security (IJIRIS) ISSN: 2349-7017(O) Volume 1 Issue 4 (October 2014) ISSN: 2349-7009(P) www.ijiris.com _________________________________________________________________________________________________ © 2014, IJIRIS- All Rights Reserved Page - 17 V. CONCLUSION Multithreading is a process where we can make the correlation between the multithreading and disconnected space of a Topological scope. The embedding of the thread in to the main threads will be helpful to justify the memory space of different threads. Life Cycle of a thread can also be described mathematically and it also obeys the properties of disconnected space. REFERENCES [1] Manoj Kumar Srivastav , Asoke Nath Mathematical modeling of various statements of C-type Language, , International Journal of Advanced Computer Research(IJACR), Vol-3,Number-1, Issue-13, Page:79-87 Dec(2013). [2] Manoj Kumar Srivastava, Asoke Nath Mathematical Description of variables, pointers, structures, Unions used in C- type language, , Joiurnal of Global Research Computer Science, Vol-5, No-2, Page:24-29, Feb(2014) [3] Manoj Kumar Srivastav, Asoke Nath, A Mathematical Modeling of Object Oriented Programming Language : a case study on Java programming language, Current Trends in Technology and Science(CTTS) Vol-3, Issue-3, Page 134- 141,(2014). [4] Manoj Kumar Srivastav, Asoke Nath, Analysis of Compilation Errors, Runtime Errors, Reliability and Validity of a Program: A Case Study on C-language : IJISET - International Journal of Innovative Science, Engineering & Technology, Vol. 1 Issue 3, May 2014. Page-281-288. [5] E Balaguruswamy- Programming with Java-TataMcGrawHill EductionP rivate Limited.,2011 [6] Sachin Malhotra, Sourabh Choudhary- Programming in Java- OXFORD University Press,2012 [7] Herbert Schildt, Java TM 2: The Complete Reference, TataMcGraw-Hill Publishing Company Limited,2001 [8] Satish Jain,Vineeta Pillai,Kratika, Introduction to Object Oriented Programming through Java,BPB Publications,2011 [9] S.K.Mapa, Real Analysis , Asoke Prakasan 1998 [10] S.K.Mapa Higher Algebra, -Sarat Book Distribution,2000 [11] K.D.Joshi-Topology.New Age International Publiocation. [12] J.N Sharma, "Topology", Krishna Prakashan Media(p)Ltd., Meerut, (2000) [13]R.S.aggarwal-Topology-S.chand publication. [14]James R Munkers-Topology- Pearson Education Asia, 2001 [15] www.javatpoint.com [16] R.D.Sharma. Mathematics class xi-. Danapat Rai Publications(P) LTD.