The paper considers the resource management system (RMS) in grid computing systems. In grid computing systems, the RMS should adopt the optimal task allocation to maximize the service provider's profit, which equals the difference between service price and service cost. Because of possible external attacks, the system should adopt self-defense to ensure the quality of service. However, the use of self-defense could have impact on service cost. Thus, the RMS must make a tradeoff. In this paper, we propose an algorithm to solve this optimization problem. Due to the consideration of external attacks and self-defense, the algorithm would be practical.