Skip to content

Instantly share code, notes, and snippets.

View tacksoo's full-sized avatar

Tacksoo Im tacksoo

  • Georgia Gwinnett College
  • Lawrenceville, GA
View GitHub Profile
@tacksoo
tacksoo / ChatClient.java
Created February 7, 2013 20:32
Simple chat server/client example
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class ChatClient implements Runnable {
// why is the ChatClient Multi-threaded?
@tacksoo
tacksoo / BankAccount.java
Created February 7, 2013 06:20
Big Java example of using the ReentrantLock
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
@tacksoo
tacksoo / Consumer.java
Created February 5, 2013 05:51
The famous producer/consumer example
public class Consumer extends Thread {
private IntBuffer buffer;
public Consumer(IntBuffer buffer)
{
this.buffer = buffer;
}
public void run() {
@tacksoo
tacksoo / Bank.java
Created February 5, 2013 05:08
Deadlock example caused by a incorrect nested synchronized block.
public class Bank {
private String name;
public Bank(String name) {
this.name = name;
}
public String getName() {
@tacksoo
tacksoo / Nondeterministic.java
Last active December 12, 2015 00:19
Simple thread interference example
public class Nondeterministic {
private int x = 0;
private int y = 1;
/*
* What happens when you synchronize only the write()?
* A synchrnoized method is like a bathroom with a door but without walls
*/
@tacksoo
tacksoo / WordCountRunnable.java
Last active December 11, 2015 23:58
Multithreaded Java program that counts how many times a certain word appears in a text file.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class WordCountRunnable implements Runnable {
private String word;
@tacksoo
tacksoo / Unresponsive.java
Last active December 11, 2015 21:48
EDT Example
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Unresponsive extends JFrame implements ActionListener{
public Unresponsive() {
@tacksoo
tacksoo / CardLayoutExample.java
Created January 24, 2013 15:01
An example of Java CardLayout
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@tacksoo
tacksoo / PizzaOrder.java
Created January 24, 2013 05:36
GridLayout Example
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
@tacksoo
tacksoo / ListWindow.java
Created April 2, 2012 12:42
ListWindow
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
/**
This class demonstrates the List Component.
*/
public class ListWindow extends JFrame
{