Post moved here: http://codeahoy.com/2016/04/03/effective-code-reviews/
java.lang.Thread class is used to create threads in Java. All code in Java executes in the context of some thread.
Source: Java Threads in 60 Seconds
Very good tax advice for startups.
Tax deadline is just around the corner. Sometimes even a straight-forward individual return can be quite a challenge. Things get more interesting when you add the business complexities associated with a small business or a startup. For many new entrepreneurs, filing taxes can be a real learning curve.
Most of us are aware of IRS audits and the associated pains. But what most entrepreneurs don’t realize is that they often overpay Uncle Sam by committing small mistakes and overlooking various tax deductions.
Keep on reading to discover common tax mistakes startups make and as a result leave hundreds, even thousands of dollars off the table — and how to avoid making them yourself.
Don’t Overpay Your Taxes – Mistakes 1to 5
In the SlideShare presentation below, we’ve listed 5 common tax mistakes startups (and small-businesses) make. Enjoy the slides and save yourself money, time and headaches.
So the main takeaway from the presentation is, and we cannot…
View original post 641 more words
Couple of days ago, I received a link from a colleague to an article. The author talked about how his company declared war on paper by taking extreme measures such as hiding printers in hard to find places and getting rid of toilet paper from bathrooms (they installed Aqua Clean WC which cleans with water).
Gotta love the modern workplace.
While I cannot think of a scenario where the use of paper should not be avoided, the reality is that paper is an important part of our modern society. It touches our lives in so many different forms – receipts, contracts, checks, warranties, packaging, lecture notes, passports to name a few.
Whether you need to store receipts for expense or tax purposes, or you love the tangible feel of taking lecture notes on paper, here…
View original post 507 more words
Must have apps for scanning and digitizing those receipts you’d need later. Scan it and toss it in the bin.
Scanning a document used to be tricky in the past – you had to access an actual scanner, load the paper and wait 10 seconds or more for the scanner to finish scanning.
These days, converting a document to PDF is almost hassle-free and doesn’t require a clumsy scanner. The apps we’re going to review in this post make scanning a breeze. The principal concept for all the apps is the same: you snap a photo of the document from the app, it detects document edges and enhances the image to look and feel like paper and exports to PDF for sharing.
It’s no surprise that CamScanner is at the top of this list — they have the largest number of users (about 50 million). Although there are lots of great features, the two best that I absolutely love are: 1) Excellent algorithm for detecting document edges inside…
View original post 247 more words
In the previous post on stopping threads, we explored thread design strategies to safely stop threads in Java. In this post, let’s look at various ways we can stop or cancel tasks handled by Executors (and ExecutorServices).
When we submit a task (Callable or its older cousin Runnable) for execution to an Executor or ExecutorService (e.g. ThreadPoolExecutor), we get a Future back which wraps the tasks. It has a method called cancel(…) which can be called to cancel the taskFuture wraps. Calling this method has different effects depending on the stage the task is in. A task could be in three possible stages after being submitted to an Executor:
- The task hasn’t started executing yet – it is waiting in the work queue for a thread to start executing it.
- A thread is executing the task.
- The task has finished executing.
Cancellation is trivial, if the task hasn’t started executed. It is simply removed from the work queue. Similarly, if the task has finished executing, cancelling it has no effect.
It is a little tricky when the task is executing in a thread. Recall from my previous post: to stop threads in Java, we rely on a co-operative mechanism called Interruption. The idea is very simple. To stop a thread, all we can do is deliver it a signal, aka interrupt it, requesting that the thread stops itself at the next available opportunity. If the thread cooperates, it will clean up itself and stop. Non-cooperating threads ignore the request and cancellation will have no effect.
boolean cancel(boolean mayInterruptIfRunning)Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.
So when the tasks is already executing and we call cancel(true) on it, it will deliver an interrupt signal to the thread executing the task. In order to make this work properly, your threads must be designed to handle interruption. Refer to this post for more info.
Sometime, it becomes necessary to support non-standard task cancellation – especially when the task relies on blocking or long-running methods that are oblivious to interruption. E.g. when you call ServerSocket.accept(), it starts waiting for a client connection. The catch-22 is that it will ignore all interruption requests and if this function is called in a thread, you cannot stop that thread using interrupts. To support nonstandard cancellation where interrupts won’t work, there are two ways of doing it. Please remember, in both of the following ways, you will have to do something to cancel the method that ignores interrupts. E.g. in the case of ServerSocket, closes the underlying socket which forces the accept() method to throw an exception.
1. Overriding Thread.interrupt():
Provide a custom ThreadFactory to the ExecutorService. Return custom Threads which override the interrupt method. For example:
Overriding interrupt() method is not recommended.
2. Overriding Future.cancel(…):
In your tasks (e.g. Callable) provide a method for non-standard cancellation, such as cancelTask(). Then override the Future.cancel(…) to call cancelTask().
But think about it: We do not normally create a Future ourselves and specify what the cancel(…) method does: we get Future when we submit a task to an ExecutorService via ExecutorService.submit(…).
Luckily, ExecutorService calls on a method called newTaskFor(Callable c) that returns the Future (or rather RunnableFuture) representing the task. Hence we need to override newTaskFor(…) to return a custom Future which overrides the cancel(…) method. This is shown below with an example:
Whereas the IdentifiableCallable is shown below:
Next we need to define our own FutureWrapper so we can override the cancel(…) method:
Now we need to define our task as follows:
That’s all. Now when we call FutureTaskWrapper.cancel(…), it will in turn call cancelTask(), where we can do our non-standard cancellation.
The entire code used in this post is available on GitHub.
Here’s my top ten list of the books I managed to read in 2013.
1. Don’t Make Me Think by Steve Krug – One of the best UI/UX design books I have ever read. Short, to the point, easy to read with lots of examples. While an excellent book, it first came out in 2001 and then in 2005, so some web design suggestions may be dated. It’s not about how to add pizzazz to your site by applying lipstick but how to make websites that are usable and doesn’t force users to think.
2. Endurance – Shackleton’s Incredible Voyage by Alfred Lansing – A compelling account of Shackleton’s incredible, but doomed voyage from England to the southern Antarctica. Heartwarming story of Shackleton’s courageous leadership skills that allowed his lost crew to survive bitter cold, darkness, constant danger for months. Highly recommended for anyone aspiring to be a leader.
3. The Snowball: Warren Buffett and the Business of Life by Alice Schroeder – I picked this up at local Chapters without knowing what to expect. Turned out to be a very good find. From an early account of Buffet’s life in Omaha, his childhood, influences, and decisions that made him the best investor in the world that he is. My only complain is that the book is huge!
4. Peopleware by Tom DeMarco – Amazing, fantastic, mind blowing guide on managing Software teams. Non-conventional, no non-sense approach to management. Couldn’t recommend it more for anyone who is a Manager or aspiring to be a Manager. In fact, it should be made compulsory for all managers to read this book every quarter.
5. Salem’s Lot by Stephen King – Not a big fan of horror fiction, but this was a great story. Spoiler Alert: Dracula in a small, sleepy New England town.
6. The Five Dysfunctions of a Team: A Leadership Fable by Patrick M. Lencioni – An excellent leadership book written as easy to read story about a dysfunctional team in an imaginary Tech company in the Valley. Short and sweet: could be read in two or three sittings.
7. Hadoop: The Definitive Guide, 3rd Edition by Tom White – An excellent resource for anyone wanting to learn Apache Hadoop. Hard to read cover to cover, the first few chapters are an excellent introduction to Hadoop. Staying on my reference shelf.
8. How to Win Friends & Influence People by Dale Carnegie – I’ve been meaning to read this book for years now. Reading about it in “The SnowBall” and that Warren Buffet went as far as enrolling in Carnegie’s seminars convinced me to finally buy it. I’ve not much to say other than it is a good book.
9. Programming in Scala by Martin Odersky – I’m into functional programming and like Scala. This is the best book on Scala written by the same homely genius who created Scala. He also runs a free online course on Scala on Coursera which I also highly recommend.
10. Enterprise Integration Patterns by Gregor Hohpe – Patterns on integrating enterprise applications using messaging and asynchronous communications. Kind of old, but very good book for understanding and building solid concepts.
What is Apache ZooKeeper?
An open-source software project for sharing data between distributed applications. It acts as a “coordination” service for distributed applications to synchronized with one another.
In a nutshell, ZooKeeper gives you the tools to help build distributed applications. For example, suppose you have a distributed web server application running on 10 nodes. Say, you want to get total real-time hit count. One way to do this is to write an application which connects to the 10 nodes, gets count from each and present the sum. Alternatively, you can have each web server application write their hit counts to ZooKeeper on regular intervals and then query ZooKeeper to get the count.
ZooKeeper supports locking, synchronization, queues, hierarchical naming service and much more, out of the box.
ZooKeeper runs on a cluster of servers. Data is replicated on nodes and is kept in memory. Clients can connect to any node to read and write, however, writes are passed to the cluster `leader`.
ZooKeeper is eventually consistent: the writes are guaranteed to be executed in the order they were received from the client, updates are atomic, and will eventually be replicated to other nodes.
ZooKeeper is widely used by some big names such as Yahoo!, Netflix, Twitter, and LinkedIn.
Redis: An Alternative?
I have used Redis in the past to coordinate and share data between our distributed applications. Redis is much faster than the ZooKeeper and extremely simple to setup. However, the issue with Redis is that it is not truly distributed in itself and problems may occur if the main Redis node fails (Although, I have been hearing about Redis cluster coming soon. Haven’t tried it though). I don’t want to get into Redis Vs ZooKeeper debate, but if you want to automatically recover from failures, use ZooKeeper. If you are sharing a lot of data at a very high rate, and you can tolerate some downtime, use Redis.
Last month I visited Santiago, Chile. It was a short business trip that lasted 5 days. at the Holiday Inn located in the financial district of Santiago. The neighbourhood was very well developed relative to other parts of the city and a lot of people were very formally dressed . The trip was excellent overall except an unfortunate event on the last day – but we’ll get to that story later.
In this blog, I would share a few pictures and stories from the trip.
Overall, people were nice and helpful. Don’t expect everyone to speak or even understand english thought the language barrier becomes annoying. In meetings, I noticed that several locals were able to understand English but were either shy or lacked confidence to hold conversations. Luckily, we had people with us who spoke both languages.
The food was ok. On my first day, I said yes to a raw meat dish since I’m a fan of tartare (and its Vietnamese version). To my surprise, I receive an *enormous* plate of minced raw meat with absolutely nothing on it, some (very hot) chillies, lemon juice and mayo on the side. It wasn’t that bad – but I wouldn’t try it again. A local burger joint called Mr. Jack has fantastic burgers. Not to mention Peruvian Ceviche which I enjoyed as well. This discussion is incomplete without mentioning Pisco Sour. I normally watch my sugar intake, but those drinks were just amazing.
Gran Torre Santiago is the tallest building in South America, which is an amazing feat considering earthquakes are common occurrences in Chile.
The weather was perfect. Not too hot, nor cold. Santiago has lots of hills and presents a nice view of snow covered Andes Mountains which looked similar to the Rockies. They have long underground tunnels for traffic.
The day I and my colleague were supposed to leave Santiago, our luggage got stolen from the vehicle. It probably happened in the parking lot of the mall we visited to buy souvenirs. We lost our luggage and everything in them. I had taken passport out of my luggage for whatever reason before I left hotel so I was lucky to at least not have that stolen. In the end, I was happy to board the flight back home and learned an expensive lesson: don’t leave your valuables in your vehicle – especially if you are going to park it in shady looking parking lot in Santiago 🙂