RUN@TIMER is an application created by me on pure innovation concept. And I am glad to announce that I was asked a number of questions on it, but I passed it all and hoping for good marks now!
1. Saurabh Jain
Assistant. Professor,CSE
OCT BHOPAL
ORIENTAL COLLEGE OF TECHNOLOGY, BHOPAL
(Formerly known as Thakral College of Technology, Bhopal)
Approved by AICTE New Delhi & Govt. of M.P. and Affiliated to Rajiv
Gandhi Proudyogiki Vishwavidhyalaya Bhopal (M.P.)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
CERTIFICATE
This is to Certify that the Minor Project Entitled “Run@Timer” Being
Submitted By Swapnil Dubey and Radhika Shrivastava in Partial fulfillment
of the Requirement for the Award Of B.E Degree In Computer Science &
Engineering To Oriental College Of Technology, Bhopal(M.P) is a Record Of
Bonafide work done by her under my Guidance.
Prof. Rachana Mishra
Head of Department, CSE
OCT BHOPAL
2. Page | - 2 -
ACKNOWLEDGEMENT
I am heartily thankful to the Management of Oriental College of Technology for providing
me all the facilities and infrastructure to take my work to the final stage.
I would like to express my deep sense of respect and gratitude towards my advisor and guide
Saurabh Jain, A.P,CSE Deptt. Oriental College of Technology, Bhopal who has given me
an opportunity to work under him. He has been a constant source of inspiration throughout
my work. His invaluable knowledge and innovative ideas helped me to take the work to the
final stage.
I express my respect to Dr. Kavita Burse, Director, Oriental College of Technology for her
constant encouragement and invaluable advice in every aspect of my academic life.
I would like to express my sincere thanks to Prof. Rachana Mishra, Head, Computer
Science Engineering Department, Oriental College of Technology and all faculty members of
Computer Science and Engineering Department for their support and guidance.
I am especially thankful to our Parents and our siblings for their love, sacrifice and support
on every path of my life..
Last but not the least I am extremely thankful to all who have directly or indirectly helped me
for the completion of my work.
3. Page | - 3 -
INDEX
1.Abstract……………………………………..
2.Introduction…………………………………
3.Brief explanation………………………………..
4.Software requirement specification…………..
i) Requirement
ii) Hardware
iii) Scope
iv) Tools used
5. Software engineering methods used……..
6. Related and proposed scenario…………….
7. Limitations and further scope……………..
8. Source codes snapshots………………………
9. Conclusions………………………………….
10. References……………………………………
4. Page | - 4 -
ABSTRACT
We now a days are so busy in handling things on our
computer systems that we often miss a task during our
work, and then realize after sometime that if we’d have
done this task results would have been different. That’s
where the application developed by me and my team
comes into existence. Run@timer is a timer application
developed in J2SE platform and takes time and task to
be done as input and then at given time performs that
task. This project report intends to give an overview of
Run@Timer, its uses and techniques. It also attempts to
identify the requirements of a good algorithm to be
followed and briefly reflects on which methods to be
used to make a good project on this topic and which
techniques are more suitable for which application.
5. Page | - 5 -
INTRODUCTION
Timer in Java is a utility class which is used to schedule
tasks for both one time and repeated execution. Timer is
similar to alarm facility many people use in mobile
phone.
Just like you can have one time alarm or repeated
alarm, you can use java.util.Timer to schedule one time
task or repeated task.
In fact we can implement a Reminder utility using
Timer in Java and that's what we are going to see in this
example of Timer in Java. Two classes java.util.Timer
and java.util.TimerTask is used to schedule jobs in Java
and forms Timer API.
TimerTask is actual task which is executed by Timer.
Similar to Thread in Java, TimerTask also implements
Runnable interface and overrides run method to specify
task details.
Timer and TimerTask example in Java Timer in Java is
a utility class form java.util package which provides
facility to schedule task at any time in future.
6. Page | - 6 -
As I said earlier, Timer is analogues to alarm clock you
setup in your smartphone. Just like alarm can be either
one time or recurring, You can also schedule task for
one time and recurring time interval using Timer API.
Timer provides method to schedule Task where task is
instance of TimerTask class, which implements
Runnable interface and overrides run() method to define
task which is called on scheduled time.
7. Page | - 7 -
SYNOPSIS
Project Name: RUN@TIMER
Project Members:
This Project is done in a group of two people. Project
members are:
1.Swapnil Dubey
2.Radhika Shrivastava
8. Page | - 8 -
BRIEF EXPLANATION
What is Timer and Timertask() in Java?
Timer class in Java maintains a background Thread
(this could be either daemon thread or user thread,
based on how you created your Timer object), also
called as timer's task execution thread.
For each Timer there would be corresponding task
processing Thread which run scheduled task at
specified time.
If your Timer thread is not daemon then it will stop
your application from exits until it completes all
schedule task. Its recommended that TimerTask should
not be very long otherwise it can keep this thread busy
and not allow other scheduled task to get completed.
This can delay execution of other scheduled task, which
may queue up and execute in quick succession once
offending task completed.
9. Page | - 9 -
Difference between Timer and TimerTask in Java:
As seen , I have seen programmers getting confused
between Timer and TimerTask, which is quite
unnecessary because these two are altogether different.
You just need to remember:
1) Timer in Java schedules and execute TimerTask
which is an implementation of Runnable interface and
overrides run method to defined actual task performed
by that TimerTask.
2) Both Timer and TimerTask provides cancel()
method. Timer's cancel() method cancels whole timer
while TimerTask's one cancels only a particular task. I
think this is the wroth noting difference between Timer
and TimerTask in Java.
10. Page | - 10 -
Canceling Timer in Java
Now talking about the cancelation of Timer task in java,
You can cancel Java Timer by calling cancel() method
of java.util.Timer class, this would result in following:
1)Timer will not cancel any currently executing task.
2)Timer will discard other scheduled task and will
not execute them.
3)Once currently executing task will be finished,
timer thread will terminate gracefully.
4) Calling Timer.cancel() more than one time will not
affect. second call will be ignored.
In addition to cancelling Timer, You can also cancel
individual TimerTask by using cancel() method of
TimerTask itself.
11. Page | - 11 -
Important points on Timer and TimerTask in Java
Now as we have got a knowledge about Timer and
TimerTask in Java, we need to remember the following
points:
1.One Thread will be created corresponding ot each
Timer in Java, which could be either daemon or
user thread.
2.You can schedule multiple TimerTask with one
Timer.
3.You can schedule task for either one time execution
or recurring execution.
4.TimerTask.cancel() cancels only that particular
task, while Timer.cancel() cancel all task scheduled
in Timer.
5.Timer in Java will throw IllegalStateException if
you try to schedule task on a Timer which has been
cancelled or whose Task execution Thread has
been terminated.
12. Page | - 12 -
When there is a need to trigger a task automatically
based on time we should schedule it using a timer api.
The requirement can vary from a single execution on a
fixed time to high complex recurring event. For
example take our regular alarm clock where we fix a
time and it beeps coming day on the fixed time.
Similarly a high complex example would be the MS
outlook where we can schedule events with a different
combination.
Following are the things in consideration
When does the event starts (first time) execution – It
may be a day / date / time in future.
Is it a one time event or a recurring event?
If recurring, what is the periodicity? –
In recurrence there are two types, like all the events
will be on a fixed time which is planned at the time of
scheduling. It may be daily / weekly / monthly / yearly /
a day of a week / alternate days / only working days.
Second type is, the recurring event can start after the
completion of previous occurrence. There can be a
delay between events.
13. Page | - 13 -
When does it end, after a constant number of
executions or after a time is reached like till Friday
only.
java.util.Timer and TimerTask :
It gives facility to schedule a task for future execution
in a background thread.
Task can be scheduled for single or recurring execution.
In recurrence, consecutive tasks will have regular
intervals.
Timer has got a cancel method using which all the
scheduled tasks can be cancelled.
Timer can be chosen to run as a daemon thread.
It can be scheduled to start with respect to current
time using fixed-delay.
TimerTask is a thread handle using which we register
tasks with the timer.
14. Page | - 14 -
Important Variations:
This api provides two important variations that needs to
be noted.
Fixed-delay
Each task execution is scheduled relative to the actual
execution time of the previous execution. So what is
actual execution?
This says that, there is no guarantee that the task will be
executed at the pre-planned time and it may be delayed
due to garbage collection or some background activity.
We should also not confuse with triggering of task and
completion of task.
Triggering is the moment at which the Timer fires start
a task. If a thread is asked to send email, it may wait for
access to the resource like mail server.
Only after the email is sent this task is considered to be
completed. We need to have this duration in mind when
we schedule recurrence tasks.
If the recurrence time is shorter and already the
previous task is not completed, the subsequent tasks
will join the queue.
15. Page | - 15 -
Fixed-rate
Here each recurring tasks are scheduled relative to the
start time of the timer.
If there is any delay in execution subsequent executions
will occur in quick succession to catch up with the
original scheduled time.
In previous case, subsequent execution will depend on
just previous execution time.
16. Page | - 16 -
Project scope:
This project is developed for anybody who is busy
doing multiple tasks on his system and wants an
application to run at a specific time but has a chance
that he might not remember to start it. Hence by using it
he can save his time, remain stress free, do his work and
leave rest on our developed application.
Methodology:
User needs to run the application. The user has a option
of “select file/Program” he wants to run at the specific
time. If the user successfully selects it, the application
asks him the time at which he want to run that
file/program. And after desired value when he clicks
OK then the timer starts and then after desired time
given by user the selected file/program execution takes
place .
17. Page | - 17 -
Software Requirements:
Netbeans
Hardware Requirements:
Processor: Preferably 1.0 GHz or greater.
RAM: 512 MB or Greater
Future Enhancements:
To make it available at Windows Market so that the
common people can also use it and take maximum
benefit of this application.
18. Page | - 18 -
SCREENSHOTS OF WORKING
APPLICATION(USER MANUAL) :
1.When the application starts it looks like this. User
sees a window in which the name of application
Run@timer is displayed and also option to Select file
/Program is there. The look and feel of the
application is made very easy to use and user
friendly.
19. Page | - 19 -
2.Then to start the application, user has to click the
Select File/Program button.
20. Page | - 20 -
3.As soon as the user clicks the button, a File
chooser window opens and we select file.
21. Page | - 21 -
4.When we open it we can browse anywhere for
file in the computer. As in this example user is
selecting music folder and then a song from that
folder.
29. Page | - 29 -
9.When the timer time which was given by user
completes, a message is displayed which says
successfully executed and then, we get this
screen.
30. Page | - 30 -
10.As the user selected the song , we can see that the
song is played as soon as the time completes.
31. Page | - 31 -
Coding Screenshots to prove the project is a pure
innovational concept and is not copied from
anywhere:
For the first frame:
1.
39. Page | - 39 -
Detailed and clear coding for the first Frame of
application:
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author swapnil dubey
*/
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.URL;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class FirstFrame extends javax.swing.JFrame {
/**
* Creates new form FirstFrame
*/
public FirstFrame() {
initComponents();
}
/**
* This method is called from within the constructor to
initialize the form.
* WARNING: Do NOT modify this code. The content of this
method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated
Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jSpinner1 = new javax.swing.JSpinner();
jSpinner2 = new javax.swing.JSpinner();
46. Page | - 46 -
Detailed coding for the second Frame:
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
/**
*
* @author swapnil dubey
*/
public class SecondFrame extends javax.swing.JFrame {
/**
* Creates new form SecondFrame
*/
public SecondFrame() {
initComponents();
startime();
}
TimerTask task = new SecondFrame.RunMeTask1();
Timer timer = new Timer();
public void startime()
{
jTextField1.setText(s);
timer.schedule(task, 0,1000);
}
/**
* This method is called from within the constructor to
initialize the form.
* WARNING: Do NOT modify this code. The content of this
method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated
Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
49. Page | - 49 -
public void run()
{
if (seconds > 0)
{
int r=seconds/60;
int rem=seconds%60;
int hr=r/60;
int rr=r%60;
if(r==0)
{
jLabel2.setText(seconds + " secs Remaining");
seconds--;
}
else if(hr==0)
{
jLabel2.setText(r+" Mins and "+rem+" secs
Remaining");
seconds--;
}
else
{
jLabel2.setText(hr+" hours "+rr+" Mins and
"+rem+" secs Remaining");
seconds--;
}
}
else if(seconds==-1)
{
return;
}
else if(seconds==0)
{
try{
File f = new File(s);
Desktop dt = Desktop.getDesktop();
dt.open(f);
}catch(IOException e){
e.printStackTrace();
}
jLabel2.setText(" Successfully Executed ");
seconds=-1;
//System.exit(0);
}
}
50. Page | - 50 -
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look
and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not
available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel
/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SecondFrame.class.getName()
).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SecondFrame.class.getName()
).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SecondFrame.class.getName()
).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException
ex) {
java.util.logging.Logger.getLogger(SecondFrame.class.getName()
).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SecondFrame().setVisible(true);
}
});
}
51. Page | - 51 -
// Variables declaration - do not modify//GEN-
BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
52. Page | - 52 -
Detailed coding for main class :
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author swapnil dubey
*/
public class main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
FirstFrame form=new FirstFrame ();
form.setLocationRelativeTo(null);
form.setVisible(true);
}
}
53. Page | - 53 -
Conclusion:
Applications like this should be developed more
frequently so that more amount of work can be done in
a short span of time and not worrying anything about
the upcoming tasks.