In this paper, we study a stock-rationing queue with two demand classes by means of the sensitivity-based optimization, and develop a complete algebraic solution to the optimal dynamic rationing policy. We show that the optimal dynamic rationing policy must be of transformational threshold type. Based on this finding, we can refine three sufficient conditions under each of which the optimal dynamic rationing policy is of threshold type (i.e., critical rationing level). To do this, we use the performance difference equation to characterize the monotonicity and optimality of the long-run average profit of this system, and thus establish some new structural properties of the optimal dynamic rationing policy by observing any given reference policy. Finally, we use numerical experiments to demonstrate our theoretical results of the optimal dynamic rationing policy. We believe that the methodology and results developed in this paper can shed light on the study of stock-rationing queues and open a series of potentially promising research.