2016-04-11_09:43 by Tony Santillanes
For the project assignment, I added a SQL statement to truncate the UserProfile table every time the program runs. I thought this would be a good solution so that the data could all be managed in the CSV file and will only insert records into the database from the file each time and not duplicate the records each time.
But, is there any easier way to do this?
Also, if there are duplicates in the csv file should the duplicates be excluded with constraints on the database as opposed to anything in the java program?
2016-04-21_21:48 by Jeff Zhuk
Threads and Thread safety are relatively small subject in a great world of Java.
Developers only deal with threads when application requirements touch system level of programming.
Nevertheless, this subject very often comes up during interview process.
My recommendation is to read more and understand what are threads and thread safety.
2016-04-22_10:15 by Tony Santillanes
package test.threads;
public class TestThread {
public static void main(String[] args) {
PrintDemo PD = new PrintDemo();
ThreadDemo T1 = new ThreadDemo("Thread - 1 ", PD);
ThreadDemo T2 = new ThreadDemo("Thread - 2 ", PD);
T1.start();
T2.start();
// wait for threads to end
try {
T1.join();
T2.join();
} catch (Exception e) {
System.out.println("Interrupted");
}
}
}
_____________________________________________________________
package test.threads;
class PrintDemo {
public void printCount() {
try {
for(int i = 5; i > 0; i--) {
System.out.println("Counter --- " + i);
}
} catch (Exception e) {
System.out.println("Thread interrupted.");
}
}
}
_____________________________________________________________
package test.threads;
class ThreadDemo extends Thread {
private Thread t;
private String threadName;
PrintDemo PD;
ThreadDemo(String name, PrintDemo pd) {
threadName = name;
PD = pd;
}
public void run() {
synchronized(PD) {
PD.printCount();
}
System.out.println("Thread " + threadName + "exiting.");
}
public void start() {
System.out.println("Starting " + threadName );
if (t == null) {
t = new Thread(this, threadName);
t.start();
}
}
}