The same kind of n jobs are processed one by one sequentially by a single machine and any number k of them may be processed as a batch. A setup time is necessary before the processing of the first job in a batch. The completion times of all the jobs in a batch are the same as the completion time of the last job in the batch and the processing time of the batch is the sum of a setup time and k times of the processing time of a job. The processing time of the job is known, but the setup time is the random variable which is distributed in the gamma distribution with the parameter whose value is unknown a priori. A conjugate prior distribution for the value is considered. The first batch size is decided by using the prior distribution, the setup time is observed, and then the second batch size is decided by using the posterior distribution revised by using the observed value of the setup time in the first batch. This process is repeated until all the jobs have been processed. The objective is to minimize the expected total completion times. This problem is formulated by using dynamic programming and both the several properties derived from the recursive equations and the critical values for the optimal strategy are derived.