How to prevent new jobs when queue size is greater than X

How to set max size of queue.