chore(task_periodic): initial commit
This commit is contained in:
parent
c6af91e64c
commit
7c62b4a95c
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
# Files
|
||||||
|
.classpath
|
||||||
|
.externalToolBuilders
|
||||||
|
.gradle
|
||||||
|
.project
|
||||||
|
.pydevproject
|
||||||
|
.settings
|
||||||
|
.sonar
|
||||||
|
*~
|
||||||
|
*.ipr
|
||||||
|
*.iml
|
||||||
|
*.iws
|
||||||
|
*.swp
|
||||||
|
*.DS_Store
|
||||||
|
*.snap.debug
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
|
||||||
|
# Directories
|
||||||
|
.idea/
|
||||||
|
.run/
|
||||||
|
.venv/
|
||||||
|
_site/
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
docs/_build/
|
||||||
|
gen-java/
|
||||||
|
gen-javabean/
|
||||||
|
gen-py/
|
||||||
|
node_modules/
|
||||||
|
target/
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Overview
|
||||||
|
This project shows periodic tasks in Java.
|
||||||
|
|
||||||
|
# Links
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<name>task_periodic</name>
|
||||||
|
<description>description</description>
|
||||||
|
<url>https://swingbe.de</url>
|
||||||
|
<groupId>org.swingbe.de</groupId>
|
||||||
|
<artifactId>task_periodic</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU General Public License</name>
|
||||||
|
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<url>https://github.com/Software-Ingenieur-Begerad/sandbox-java</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- Other properties -->
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- Target Java versions -->
|
||||||
|
<release>11</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<!-- exclude signatures from merged JAR to avoid invalid signature messages -->
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.SF</exclude>
|
||||||
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
<!-- The shaded JAR will not be the main artifact for the project, it will be attached
|
||||||
|
for deployment in the way source and docs are. -->
|
||||||
|
<shadedArtifactAttached>true
|
||||||
|
</shadedArtifactAttached>
|
||||||
|
<shadedClassifierName>shaded</shadedClassifierName>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>de.swingbe.task_periodic.Main
|
||||||
|
</Main-Class>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,35 @@
|
||||||
|
package de.swingbe.task_periodic;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello world!");
|
||||||
|
|
||||||
|
//instantiate Timer object
|
||||||
|
Timer time = new Timer();
|
||||||
|
|
||||||
|
//instantiate ScheduledTask class
|
||||||
|
ScheduledTask st = new ScheduledTask();
|
||||||
|
|
||||||
|
//create repetitively task for every 1 secs
|
||||||
|
time.schedule(st, 0, 1000);
|
||||||
|
|
||||||
|
//for demo only.
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
System.out.println("Execution in Main Thread...." + i);
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.out.println("Another thread has interrupted this one");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (i == 4) {
|
||||||
|
System.out.println("Application Terminates");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.swingbe.task_periodic;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class ScheduledTask extends TimerTask {
|
||||||
|
|
||||||
|
//to display current time
|
||||||
|
Date now;
|
||||||
|
|
||||||
|
//ddd your task here
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
//initialize date
|
||||||
|
now = new Date();
|
||||||
|
|
||||||
|
//display current time
|
||||||
|
System.out.println("Time is :" + now);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue